Click here to Skip to main content
16,007,472 members
Home / Discussions / C#
   

C#

 
GeneralRe: Form.Hide(), or Form.Close() not working Pin
Dave Kreskowiak6-May-05 12:08
mveDave Kreskowiak6-May-05 12:08 
GeneralNewly created file stays locked Pin
dratcha6-May-05 9:46
dratcha6-May-05 9:46 
GeneralRe: Newly created file stays locked Pin
Colin Angus Mackay6-May-05 10:52
Colin Angus Mackay6-May-05 10:52 
GeneralRe: Newly created file stays locked Pin
dratcha6-May-05 11:18
dratcha6-May-05 11:18 
GeneralForm Show() method hangs, does not display controls Pin
methodincharge6-May-05 7:26
methodincharge6-May-05 7:26 
GeneralRe: Form Show() method hangs, does not display controls Pin
S. Senthil Kumar6-May-05 7:59
S. Senthil Kumar6-May-05 7:59 
GeneralRe: Form Show() method hangs, does not display controls Pin
methodincharge6-May-05 8:46
methodincharge6-May-05 8:46 
GeneralRe: Form Show() method hangs, does not display controls Pin
S. Senthil Kumar6-May-05 20:12
S. Senthil Kumar6-May-05 20:12 
I think not calling BeginInvoke is the problem. To know why, you have to understand how Windows messages work. Basically, any action that you do on the UI, like clicking on a button, gets translated to a message and is posted to the application's message queue. Every Winforms application is provided with a thread on startup, whose only job is to process messages in the message queue, also called message pumping. Without processing messages, none of the UI commands will go to their handlers, in fact, the window itself won't get rendered properly. Your event handler runs on a thread pool thread, which doesn't have a message pump and that's why you get a half drawn window.

In .NET, Application.Run(...) in the Main method of any Winforms application does the message pumping.

Do you have a reference to the main form (or one of the controls in that form) inside ProcessTextMessage? If so, you can just do
private delegate void ProcessTextMessageDelegate(string text);
private void ProcessTextMessage(string text)
{
   if (control.InvokeRequired)
   {
      control.BeginInvoke(new ProcessTextMessageDelegate(ProcessTextMessage), new object[] {text});
      return;
   }

   form.Show();
}

control is either the Form object or some control that is in the form. The above piece of code results in another call to ProcessTextMessage, but this time on the UI thread (which means there is a message pump).
In the second call, InvokeRequired will be false, so it won't go inside the if block.
If you want to know more about BeginInvoke/InvokeRequired, you can take a look here[^]

Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
GeneralWindows Form Multiline ListView Pin
rana936-May-05 7:23
rana936-May-05 7:23 
GeneralWinForms Datagrid format based on cell value Pin
Jose Guay6-May-05 7:14
Jose Guay6-May-05 7:14 
GeneralRe: WinForms Datagrid format based on cell value Pin
Polis Pilavas6-May-05 8:14
Polis Pilavas6-May-05 8:14 
GeneralRe: WinForms Datagrid format based on cell value Pin
Jose Guay6-May-05 12:04
Jose Guay6-May-05 12:04 
GeneralRe: WinForms Datagrid format based on cell value Pin
Polis Pilavas6-May-05 12:14
Polis Pilavas6-May-05 12:14 
GeneralOffice Addin C# Pin
Member 18788066-May-05 6:49
Member 18788066-May-05 6:49 
Generalis there any good programmer for that to help me Pin
snouto6-May-05 5:52
snouto6-May-05 5:52 
QuestionDouble-clicking the Desktop opens the Start Menu? Pin
jklucker6-May-05 5:49
jklucker6-May-05 5:49 
GeneralUpdating values in a PropertyGrid Pin
WujekSamoZlo6-May-05 5:23
WujekSamoZlo6-May-05 5:23 
GeneralRe: Updating values in a PropertyGrid Pin
Mathew Hall6-May-05 15:28
Mathew Hall6-May-05 15:28 
Generalnewbie handling user controls click event in form Pin
Chenele6-May-05 5:11
Chenele6-May-05 5:11 
GeneralRe: newbie handling user controls click event in form Pin
Doctor Nick6-May-05 5:53
Doctor Nick6-May-05 5:53 
GeneralRe: newbie handling user controls click event in form Pin
Chenele6-May-05 6:44
Chenele6-May-05 6:44 
GeneralRe: newbie handling user controls click event in form Pin
MoustafaS6-May-05 9:03
MoustafaS6-May-05 9:03 
GeneralRe: newbie handling user controls click event in form Pin
Chenele6-May-05 9:16
Chenele6-May-05 9:16 
GeneralRe: newbie handling user controls click event in form Pin
S. Senthil Kumar6-May-05 8:02
S. Senthil Kumar6-May-05 8:02 
GeneralLZX or MSZIP Compressing Algorithms Imprementations Pin
Stanimir_Stoyanov6-May-05 4:26
Stanimir_Stoyanov6-May-05 4:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.