Hi, everyone. I ran into an UI freeze issue with threading and
simplied the problem down to the following sample code. The logic is
as follows:
1. The main UI thread creates a non-UI STA thread(m_MainTh read).
2. Then the non-UI thread runs and creates derived winform and holds
a reference to the winform. NOTE: I don't call Application.Run ()
because I don't need a message pump on this "hidden form" in my
application. I rely on the form's STA thread owner to pump and
dispatch non-COM messages to the form window on a WaitOne() call.
This works fine. I can send and receive messages to external win32
process using the hidden form.
The code below works fine in .NET 1.1, but causes UI freeze issue
in .NET 2.0 outside of the debugger. To produce the freeze behaviour,
I do the following:
1. Run the code below
2. Click on the Start button to create the non-UI thread(which
creates the hidden form)
3. right click on Desktop -Properties -Settings -change your
screen resolution to something less and click OK
4. When asked if you want to keep the setting, click NO to go back.
At this point, you will notice that the main form is now
frozen(verified with spy++ that it doesn't get any messages). It
looks like it's deactivated somehow. You can't move the window and
the form won't paint properly if you overlap it with another window.
The same code below doesn't have the problem in .NET 1.1. Also, the
problem doesn't occur in .NET 2.0 if you run it under the debugger.
If I don't create the hidden winform, there is no problem.
Can someone explain what's happening? Thanks.
=============== == Code Starts Here =============== ==
public partial class Form1 : Form
{
AutoResetEvent m_MainThreadSto pEvent = new
AutoResetEvent( false);
Thread m_MainThread = null;
HiddenForm m_WorkerHiddenF orm = null;
public Form1()
{
InitializeCompo nent();
}
private void Start()
{
m_MainThread = new Thread(new
ThreadStart(Mai nThreadStart));
m_MainThread.Na me = "My Main Thread";
m_MainThread.Se tApartmentState (ApartmentState .STA);
m_MainThread.St art();
}
private void Stop()
{
m_MainThreadSto pEvent.Set();
}
private void MainThreadStart ()
{
System.Diagnost ics.Debug.Write Line("Created Main
Thread ... " + DateTime.Now.To LongTimeString( ));
m_WorkerHiddenF orm = new HiddenForm();
while (!m_MainThreadS topEvent.WaitOn e(5000, true))
{
System.Diagnost ics.Debug.Write Line("::MainThr ead ... "
+ DateTime.Now.To LongTimeString( ));
}
m_WorkerHiddenF orm.Close();
System.Diagnost ics.Debug.Write Line("Stopped Main
Thread ... " + DateTime.Now.To LongTimeString( ));
}
private void btnStart_Click( object sender, EventArgs e)
{
Start();
}
private void btnStop_Click(o bject sender, EventArgs e)
{
Stop();
}
private void Form1_FormClosi ng(object sender,
FormClosingEven tArgs e)
{
Stop();
}
}
public class HiddenForm : Form
{
int m_WindowHandle;
public HiddenForm()
{
m_WindowHandle = this.Handle.ToI nt32();
}
protected override void WndProc(ref Message msg)
{
base.WndProc(re f msg);
}
} 0 2012 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: someone |
last post by:
Hi,
We are encountering a problem with the DTPicker. This is the situation:
We have a DTPicker-control on a VB6 Active-X.
The Active-X is used on a .NET winform.
the problem:
The .Net winform is:
1. instantiated
|
by: Brian |
last post by:
Hello,
I usually login a forum and post some messages. I can't directly post
message because the forum ask me to login first. I guess it need some
session information.
Now I want to program a C# WinForm to do it. But I heard that the session
controll in WinForm and IE are different. Is it possible that I let my
WinForm app login first and then post my messages?
Thanks.
|
by: Stan Sainte-Rose |
last post by:
Hi,
Newbie I am, I need to understand something with vb.
I have a winform (A) where the user fills out some datas.
On this form, I have a combo box where he can select an item.
If the item doesn't exist, I would like he creates it by clicking on a
button.
At this point, I open a new winform (B) where he can do it.
So my question is, How can I retrieve this new data on the winform (A).
The new data have to be added on the combobox and...
|
by: Alien2_51 |
last post by:
I have a problem with a ListBox control that is on a TabControl, it seems to
be forgetting which items are selected in the list when I tab off the current
tab, here's my winform code... I even added a click event handler that resets
the selected items based on whats in the collection it is data bound to...
I'm baffled, pounding my head against the wall, it's not working... Please
help...
I tried posting the code but it was too long,...
|
by: Stan |
last post by:
I need to attach to aspnet_wp.exe in order to debug a web serivice from
WinForm client. Why don't I have to do this for ASP.NET / WebForm client?
Why doesn't VS.NET debugger attaches automatically? Can I configure it?
Thanks,
-Stan
| |
by: Annie |
last post by:
hello guys,
I have a number of checkbox contorls all together (I don't want option
buttons - users request) ... I just want
the users be able to select only one of the checkboxes ... if a checkbox is
selected and the users
select another one it should decheck the selected one and check the other
....
Is it possible in vb.net to group them?
|
by: Galen Somerville |
last post by:
Tooo many examples. I'm confused.
VB6 ActiveX.dll with no windows or controls. Interfaces with a device that
returns an x size byte array every x milliseconds for x counts. Sends a
message to VB2005 main thread on each count.
VB2005 has to start the thread and set several variables in the thread
before loop starts.
VB2005 then has to respond to messages and draw on screen until last count
|
by: jjbutera |
last post by:
I know how to use the ErrorProvider in my winforms..or do I? I validate
the values and set the ErrorProvider in the validating event. If not
valid, I set e.Cancel = True. I clear the ErrorProvider in the
validated event.
Is there a way to know if all validated controls pass validation when
the user clicks an OK button? In ASP.Net there's the Page.IsValid
method. Is there something similar in winforms, or do I still have to
write an...
|
by: zou |
last post by:
there is a file which is very large,
we can use stat to get a file size(<2G),
struct stat buf;
stat("file", &buf);
long s=(long)stat.st_size;
but stat::st_size is type of off_t(typedef long),
so how about a file larger than 2G?
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |