ShowInTaskbar Causing Blank Form/Hang

M

Mike

I have a winforms application that is hidden using the following code
upon prompt:

//Remove from the taskbar and also from alt+tab
this.Visible = false;
this.ShowInTaskbar = false;
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;

Upon correct DDE prompt from another application my application should
show itself in normal state with an icon in the taskbar.

this.Show();
this.Visible = true;
this.WindowState = FormWindowState.Normal;
this.Focus();
//this.ShowInTaskbar = true;
LoadFormData();

Problem: If I do not comment out this.ShowInTaskbar = true when
re-opening my form just hangs. I cannot even access maximize or
minimize buttons. If I comment out this.ShowInTaskbar everything seems
to work correctly EXCEPT there is nothing in the taskbar. I have tried
changing the order of the calls for a show but nothing seems to help.

Any suggestions on what might be occurring and how to resolve it would
be accepted with relish!

Mike
 
M

Mehdi

I have a winforms application that is hidden using the following code
upon prompt: [...]
Upon correct DDE prompt from another application my application should
show itself in normal state with an icon in the taskbar. [...]
Problem: If I do not comment out this.ShowInTaskbar = true when
re-opening my form just hangs. I cannot even access maximize or
minimize buttons. If I comment out this.ShowInTaskbar everything seems
to work correctly EXCEPT there is nothing in the taskbar. I have tried
changing the order of the calls for a show but nothing seems to help.

Just an idea out of the blue: are you sure that both the code that hide
your form and the one that shows your form again are executed in the UI
thread of your application?
 
M

Mehdi

No, I'm not sure. How would you advise I check? Thanks much.

The easiest way to check that is to check the value of the InvokeRequired
property of your form. If it returns false, this means that you are in the
UI thread and that you can safely call its methods.

If it returns true however this means that you are not in the UI thread and
that, as stated in the documentation, you should first marshall the call to
the UI thread using the Control.Invoke or Control.BeginInvoke methods
before accessing any method or property of a UI control.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top