473,395 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Deadlock with worker thread making a control visible

Was able to reproduce this with a simple example (using .NET 1.1):

1) Create a new WindowsApplication project
2) Add a button to the form and set its Visible property to false
3) Double click on the form to add Form1_Load handler
3) Add the following code to Form1:

private delegate void DoAsync();
private void Form1_Load(object sender, System.EventArgs e)
{
new DoAsync(DoIt).BeginInvoke(null, null);
}
private void DoIt()
{
this.button1.Visible = true;
}

The main thread will lock up for about 5 minutes or more.
Can someone explain what's happening here to me?
I'm using this method to set all sorts of properties on all sorts of
controls, it's just the Visible property that's causing me grief.
How do I solve this?
In Win32 I might post a user message, can you do that in .NET?
Oct 16 '06 #1
2 1549
Hi,

You have to use Control.Invoke

A UI control cannot be accessed from other than the UI thread.
--
Ignacio Machin
machin AT laceupsolutions.com

"Douglas Peterson" <Te******@nospam.msn.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Was able to reproduce this with a simple example (using .NET 1.1):

1) Create a new WindowsApplication project
2) Add a button to the form and set its Visible property to false
3) Double click on the form to add Form1_Load handler
3) Add the following code to Form1:

private delegate void DoAsync();
private void Form1_Load(object sender, System.EventArgs e)
{
new DoAsync(DoIt).BeginInvoke(null, null);
}
private void DoIt()
{
this.button1.Visible = true;
}

The main thread will lock up for about 5 minutes or more.
Can someone explain what's happening here to me?
I'm using this method to set all sorts of properties on all sorts of
controls, it's just the Visible property that's causing me grief.
How do I solve this?
In Win32 I might post a user message, can you do that in .NET?


Oct 16 '06 #2
Thank you!
Douglas

"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comwrote in
message news:ui**************@TK2MSFTNGP02.phx.gbl...
Hi,

You have to use Control.Invoke

A UI control cannot be accessed from other than the UI thread.
--
Ignacio Machin
machin AT laceupsolutions.com

"Douglas Peterson" <Te******@nospam.msn.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>Was able to reproduce this with a simple example (using .NET 1.1):

1) Create a new WindowsApplication project
2) Add a button to the form and set its Visible property to false
3) Double click on the form to add Form1_Load handler
3) Add the following code to Form1:

private delegate void DoAsync();
private void Form1_Load(object sender, System.EventArgs e)
{
new DoAsync(DoIt).BeginInvoke(null, null);
}
private void DoIt()
{
this.button1.Visible = true;
}

The main thread will lock up for about 5 minutes or more.
Can someone explain what's happening here to me?
I'm using this method to set all sorts of properties on all sorts of
controls, it's just the Visible property that's causing me grief.
How do I solve this?
In Win32 I might post a user message, can you do that in .NET?



Oct 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: mk | last post by:
You probably suspect the answer, typically its 'yes' deadlock can occur in any multithreaded application. Even ones that employ static members. Commonly it occurs when more than one thread tries...
12
by: Joey Powell | last post by:
Re: Original post = Windows forms - how do I get them to render/update properly? from August 22. Okay I am making some progress with being able to use delegates to run my shelled processes on...
5
by: Stephen Lamb | last post by:
I have a background worker thread which I start from a form's HandleCreated event that makes calls back to the form using Invoke. During shutdown the form is disposed and the background worker...
4
by: Sefi | last post by:
Good day everyone I'm a bit confused about whether the "Server Application Unavailable" status of my website that frequently occurs when several users are simultaneously logged into it is a symptom...
7
by: Charles Law | last post by:
My first thought was to call WorkerThread.Suspend but the help cautions against this (for good reason) because the caller has no control over where the thread actually stops, and it might have...
2
by: Jürgen Devlieghere | last post by:
Hi, We are creating event-driven multi-threaded applications on a daily basis. To help us solving deadlocks, we implemented a CriticalSection class that does dead-lock detection: an attempt to...
6
by: Joe Jax | last post by:
I have an object that spawns a worker thread to process one of its methods. That method processes methods on a collection of other objects. During this processing, a user may request to cancel the...
0
by: Gordon Cone | last post by:
I am currently debugging a deadlock in a multithread C# application. It makes lots of calls to legacy unmanaged code. The application runs on windows sever 2003 and uses the sever version of the...
0
by: Gordon Cone | last post by:
I am currently debugging a deadlock in a multithread C# application. It makes lots of calls to legacy unmanaged code. The application runs on windows sever 2003 and uses the sever version of the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.