|
You are not doing anything wrong, this is a bug in the framework. When Application.Run finishes, a bit is set indicating that the message pump on the thread has shutdown. This bit is sticky, and any subsequent calls to Application.Run see this bit set and immediately terminate.
However, this should workaround your problem:
static void Main()
{
ServerOrClientForm serverOrClient = new ServerOrClientForm();
Application.Run(serverOrClient);
serverOrClient.ShowDialog();
serverOrClient.InputSelection();
UserInterface ui = new UserInterface();
Application.Run(ui);
// pass information to and from ui
obj = ui.GetInfo();
// ...
ui.SetInfo(obj);
}
|
|
|
|
|
Thank you very much for your reply! Regrettably, your solution does not work for me. It still behaves as it did before. I have changed the code into the following:
static void Main()
{
ServerOrClientForm serverOrClient = new ServerOrClientForm();
serverOrClient.ShowDialog();
serverOrClient.InputSelection();
System.Threading.Thread.Sleep(1000);
UserInterface ui = new UserInterface();
ui.ShowDialog();
}
I can clearly see the second form flashing by after the 1 second delay. The first form, however, works fine.
|
|
|
|
|
Please look at the code I had posted. For the "UserInterface" class, do not use ShowDialog(), but rather Application.Run(ui).
|
|
|
|
|
I have tried that, and it did not work either. That's why I tried to use ShowDialog() on both of them.
|
|
|
|
|
What does the function "InputSelection" do?
In a simple test application, this works fine for me:
static void Main()
{
Form1 form1 = new Form1();
form1.ShowDialog();
Application.Run(new Form2());
}
|
|
|
|
|
I found the source to my troubles. When the user presses the OK button in my ServerOrClientForm its clicked handler issued a call to Application.Exit(). Now I call this.Close() instead, which obviously was the better choice. But I am not sure why. Do you know why?
InputSelection is just a way of blocking the caller until ServerOrClientForm has completed its task (merely a busy-wait loop in which I am checking a 'done' flag and if it's not set, put the thread to sleep for a little while). The thing is, I want the form to produce a result and then feed that result to anyone that call theForm.GetResult, and at the same time block the caller until the result is ready. Can you come up with a good solution?
Thank you very much for helping me with my original problem.
|
|
|
|
|
Application.Exit posts the WM_QUIT message which signals to windows to shut down (note, that's "windows", not "Windows"). The application will ultimately exit.
It's typically not a good idea to call Application.Exit .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hi,
I use form.Hide() to hide a form, and use form.Show() to bring it back. However, I found that the form's position is changed. How did this happen? I didn't recreate this form, just hide and show again.
How can I keep it as where it was?
Thanks!
|
|
|
|
|
I found this from msdn about "Form.WindowState Property"
Before a form is displayed, the WindowState property is always set to FormWindowState.Normal, regardless of its initial setting. This is reflected in the Height, Left, Top, and Width property settings. If a form is hidden after it has been shown, these properties reflect the previous state until the form is shown again, regardless of any changes made to the WindowState property.
I think this is the reason, my form keeps changing position. But How can I keep it stay where it was?
Thanks in advance.
|
|
|
|
|
You could set some variables to the co-ordinaets of your form when you hide it, then when you show it, re-set the form's position to those variables.
i.e.
Point loc = this.Location;<br />
this.Hide();
//Showing
this.Show();<br />
this.Location = loc;
Not a great solution but would work till you can get a better one.
Kev
Robert E. Lee's Truce
Judgement comes from experience; experience comes from poor judgement.
|
|
|
|
|
|
can anyone tell me ho do i play and stop either a wma ...mp3...wav file....without using the media player ocx...
|
|
|
|
|
You might wanna try looking into DirectX 9 SDK.
The Microsoft.DirectX.DirectSound namespace (I think this is correct) has what you need.
Try searching MSDN for documentation.
Kev
Robert E. Lee's Truce
Judgement comes from experience; experience comes from poor judgement.
|
|
|
|
|
Do any one know what is the meaning of declaring a class with public access specifier?
|
|
|
|
|
Without it the class is not visible outside of the assembly.
|
|
|
|
|
|
hey...i have this big qustion...like...i have seen in quite a few application..whcih when u install them....they add theier own tabs buttons,controls,,etc to windows forms...like i installed an alarm software in x the other day and it added its own tab tothe form that pops up when you double clcik....the....system tray date time....how do i dow this.....
|
|
|
|
|
Mridang Agarwal wrote:
the....system tray date time....how do i dow this.....
It was a little hard to decipher your question, it wasn’t very clear but I assume you are talking about adding a notification icon to the systray. You need to look into the NotifyIcon Class[^].
- Nick Parker My Blog | My Articles
|
|
|
|
|
that not what i mean....u see....when u double clcik the date time(in win xp)...in the system tray a windows pops up....it has three tabs, namely....time.....timezone....and...syncronise time....now.....what i wanna do..is to add my own applications tab there...how dod i do that....
|
|
|
|
|
hello guys
i have implemented a collection which is derived from CollectionBase and create a control which has a Collection property like this:- eek:
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
EditorAttribute("typeof(CollectionEditor)","typeof(System.Drawing.Design.UITypeEditor)")]
public MyCollection ButtonList
{
get
{
return (MyCollection)myObject;
}
set
{
this.myObject= value;
}
}
eek:
but the prblem is when i add the property values using Collection Editor it sets the values for the control but when i rebuild the project it reset the control property null. how can i resolve this problem or is there any place where Collection Editor store their values please help me.
thanx:
|
|
|
|
|
I am adding a chacracter to a string depending on the length of the text in a text box. Unfortunately this move the cursor to the beggining of the text in the text box, how do i move the cursor back to the end??
Kev
Robert E. Lee's Truce
Judgement comes from experience; experience comes from poor judgement.
|
|
|
|
|
TextBox tb = new TextBox();
tb.SelectionStart = tb.Text.Length;
|
|
|
|
|
Works great, thanks
Kev
Robert E. Lee's Truce
Judgement comes from experience; experience comes from poor judgement.
|
|
|
|
|
I added my entire C# project to source control (CVS in this case) and am now realising that there are probably files in the project tree that shouldn't be checked in, since their generated locally (such as user settings, or build temp files)
Can anyone give me a list of all the files that shouldn't be in source control?
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|
|
I always put in my cvs repository only the source files. I never put project files and debug files. This way I am able to use another IDE to keep progamming when I dont have visual studio or csharpdevelop.
You can put, source files, image files, resource files, and database file (once you use access ou dbf as database).
That is it, sorry my poor english.
Thiago - Brazil.
|
|
|
|