|
At first glance, it would seem the problem is that you're not closing the first TcpChannel . When you instantiate a new one, the first TcpChannel remains active until the GC finalizes it - assuming nothing else is referencing it. This will happen when 1) your machine is idle, 2) when memory is or is nearly exhausted, or 3) when you call GC.Collect (not a good idea since this is a synchronous (i.e., blocking) call that may take a while). Be sure to call TcpChannel.StopListening .
You actually shouldn't need to re-allocate the channel, though. IF the remoting object is not listening the channel does nothing. You would have an open port, but a port that goes no where. Just something to consider.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks a lot for helping. I added TcpChannel.StopListening, but it didn't work. The TcpChannel does remain active (as you assumed), because it is a member variable. So the old TcpChannel exists when I create a new instance of TcpChannel to the same member variable. I'm a neebie to remoting (and to also C#), so I don't really know what's going on, so the reason for the member variable is that I can use it to UnregisterChannel when I disconnect. Can I avoid using member variable and get the current tcpchannel somehow for unregistering or what should I do when I disconnect in order to be able to reconnect? Also, could I change the port in the current TcpChannel when it is not registered or listening with out creating a new instance of it?
Thanks
|
|
|
|
|
Re-instantiating it creates a new instance and assigns that instance to the field ("member variable" as you called it, which is incorrect, BTW). The old field - if nothing else references it - will be finalized (destroyed) eventually, but there's no garuantee when). Don't re-instantiate it.
Actually, you should consider using .config files to configure remoting. If you ever need to change properties, a server address, or the remoting object base location with how you're doing it now, you would have to change your code, re-compile, and test it all over again. If you use .config files the RemotingConfiguration.Configure method you get everything you did without the hastle and in a way that you can change just by editing the .config file (an XML file) and re-starting the application. If you implement two different AppDomains with one watching for changes to the file, you can take-down the other AppDomain that hosts the remoting object and re-start it. This is basically how ASP.NET works (when you edit Web.config the ASP.NET web application is reloaded, or all ASP.NET web applications are reloaded if you edit the machine.config or the virtual host's root Web.config file).
I recommend picking up a good book on Remoting, like Microsoft .NET Remoting[^] (for beginners and intermediate developers) from MS Press and/or Advanced .NET Remoting[^] from Ingo Rammer.
.NET Remoting is complex and very abstract. Either of these books can really help sort-out the details and give you ideas about how to better implement a remoting solution.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I have a usercontrol with 2 basic .NET controls (one label and one textbox for example).
When i drop such a control on a form in design time, everything is fine, i can click on it anywhere to select it, resize it, etc.
But now when i try to drop a panel on the form and drag/drop my UserControl into the panel, then i can't select the UserControl anymore. Designer seems to be trying to select the inner control (the textbox or the label) but also fails. When i click on the textBox part of the usercontrol, then i can type text in, as if textbox was in runtime.
I'd have thought it would be a known issue, but i couldn't find anything about it, nor could i find a workaround. Could anyone help, please ?
Thannk you !
Etienne.
|
|
|
|
|
just check in the Form Designer Code whether the following line is present?
this.panel1.Controls.Add(this.userControl1);
where panel1 and userControl1 are the panel's name and userControl names respectively.
I tested the scenario explained by you..No problem at my end..........
|
|
|
|
|
Interesting... The issue is the same on a co-worker computer, but he has the same VS version.
I made an archive with 2 projets (Solution containing both is in Test-Bug) showing the issue.
There is a form in Test-Bug, with a panel, which contains a UserControl. Now if i select the UserControl, drag it out of the panel, parent changes and is serialized ok in InitializeComponents. (i do have the right "Controls.Add" line) But then if i de-select usercontrol, and click on the textBox again, it won't select the UserControl (cursor changes as if over a textbox, too), but the focus will go inside the textBox, allowing to type in text at design time.
Once this happened, if i quit the solution and load it back, everything is back to normal.
Thanks a lot for looking into this, i really don't understand.
Here's a link to the sample code i made :
UserControl bug ?
Etienne.
|
|
|
|
|
I do not have winRaR. that is why, I could not un-concompressed your userControl,
whereas, I re-checked the my demo userControl,
1.It does allow to write in the TextBox. But the changed text is reset after The project is being compiled.
2.It allows to select the userControl, in both the cases (user control being kept inside the panel,or outside the panel).
I am sorry, I could not minutely tested the scenario, previously....Seems to be a bug..
|
|
|
|
|
Again re-checked using UpDownControl inside an userControl. When it is dragged into the panel or dragged out of the panel. The constituent controls of the userControl starts behaving similar to the run-time.
When the project containing the userControl is being re-compiled. The problem goes.......strange.....!!!
|
|
|
|
|
Thanks a lot for taking so much time on this.
Indeed, whatever the control you have inside the UserControl is, it will begin to act as if in run-time. And all is back to normal upon recompilation or quit/reload.
Does anyone know a work-around ? any code to add to the UserControl and/or Designer ? Cause it's a pain having to re-compile so often when creating forms in design mode...
Anyway, thanks again Jay ! (look into 7-zip, it's free and handles rar files)
Etienne.
|
|
|
|
|
I found a workaround that works for me :
Override OnParentChanged in your UserControl, and for every control contained in it, remove it and add it again. You may limit this code section to DesignMode, so it won't happen at runtime.
Etienne.
|
|
|
|
|
Great.....It works...
By the way, Is this bug being already detected by the Microsoft? or being recorded by the Microsoft?
|
|
|
|
|
Hi everybody!
I've performed recording wave sound in low level (by API function) but I have a problem. In WndProc function, the MM_WIM_DATA message is occured but the buffer is not filled. Could you help me.
Thanhks
Hung
|
|
|
|
|
Read the docs about MM_WIM_DATA on MSDN: this message is also sent when waveInReset is called, so you need to check the dwFlags on the WAVEHDR structure.
Yes, even I am blogging now!
|
|
|
|
|
hi guys, I wish to find out the way to remove the whitespaces in a string
e.g "James Bond"
|
|
|
|
|
Check out the "Replace" method of the string class...
Etienne.
|
|
|
|
|
thankz for the reply, i tried using str.Replace(' ', ''); but its not possible. I need to remove all the white spaces within the string so that i can compare the string to another string.
|
|
|
|
|
string input = "How_are_you_Mr._k o b e z t 0 8? ";
input = input.Replace(" ", string.Empty);
MessageBox.Show(input);
|
|
|
|
|
tried this
string c1 = lstContent1.SelectedItem.ToString();
string c2 = lstContent2.SelectedItem.ToString();
c1 = c1.Replace(" ", string.Empty);
c2 = c2.Replace(" ", string.Empty);
System.Console.WriteLine("c1 = " + c1);
OutCome still the same
"1" "James" "Bond"
tried using c1 = c1.Replace(' ', string.Empty);
but got D:\My Documents\Visual Studio Projects\New-FYP (Try-Out) 2\Form1.cs(372): Argument '2': cannot convert from 'string' to 'char'
|
|
|
|
|
Then your "whitespaces" probably aren't spaces ( (char)32 ).
Try scanning your string characters and find out what char the "whitespace" is. Might be a \t or something. Then once you found out, you can use replace. Replace does work, and your code is right. So only thing left is that you have actually no space in your string.
Etienne.
|
|
|
|
|
string temp3 = c1[3].ToString();
string temp3a = c1[3].GetTypeCode().ToString();
System.Console.WriteLine("c1 = " + temp3);
System.Console.WriteLine("c1 = " + temp3a);
Outcome:
c1 =
c1 = Char
weird although it's stated as a char, it is a Tab in the .txt file when i check. is there any way to remove it then?
the format in the .txt file is this
"S_N" "Last_Name" "First_Name"
"1" "Yi Zhuang" "Tan"
"2" "Kai Wong" "Lei"
the file is created by exporting a access database table into a txt file
|
|
|
|
|
well, Tab is a character like any other, no strange thing about it.
If you want to be absolutely sure about the ascii code, try this :
char test = c1[3];
int test_ascii = Convert.ToInt32(test);
MessageBox.Show(test_ascii.ToString());
Write down the number the MessageBox will show, then back to your replace code, use :
int the_number_you_got;
my_string.Replace( ((char)the_number_you_got).ToString(), String.Empty);
Etienne.
|
|
|
|
|
Yes it's working now thankz so much for the help
will be coming here to post question again when i start on the reading and comparing of xml data wif .txt data
|
|
|
|
|
Yes it's working now thankz so much for the help
will be coming here to post question again when i start on the reading and comparing of xml data wif .txt data
|
|
|
|
|
I have an application that reads the registry value and diplays result in a textbox (Using Microsoft.Win32 namespace). It works fine as long as I know the registry name. Here is my problem:
1. I have a subkey name MyKey (HKLM\SOFTWARE\MyKey)
2. The key will have one or two subkeys but I do not know their names(lets call them KeyX, KeyY)
3. Every unknow key (e.g. KeyX)has a string value that I want to read
serviceName 12345
Any ideas how to do this?
|
|
|
|
|
You can call GetValueNames() to retrieve the names of the values and GetSubKeyNames() to retrieve the names of the subkeys.
Yes, even I am blogging now!
|
|
|
|