473,785 Members | 2,395 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Threaded UI

I've got a situation where I need to display a modal dialog from within a
background processing thread. The problem I'm having is that it needs to
display as a modal window to the thread's parent GUI app. When I try this I
get a pseudo-modal dialog (more like a top-level window)... the dialog is
always on top of the parent app's window, but the user can still access the
parent window and its controls.

Is there any way to accomplish true modal dialog functionality when opening
a dialog from within a separate thread?

Thanks,
Todd
Mar 16 '06 #1
4 1371
On Thu, 16 Mar 2006 08:38:39 -0800, Todd wrote:
I've got a situation where I need to display a modal dialog from within a
background processing thread. The problem I'm having is that it needs to
display as a modal window to the thread's parent GUI app. When I try this I
get a pseudo-modal dialog (more like a top-level window)... the dialog is
always on top of the parent app's window, but the user can still access the
parent window and its controls.

Is there any way to accomplish true modal dialog functionality when opening
a dialog from within a separate thread?


Place the code showing the modal dialog in a function then marshall the
call of this function to the UI thread using the Invoke method of any
control that has been created in the UI thread. The result will be just
like if you had shown the modal dialog from the background thread and the
dialog will behave properly. You should also create the dialog object
itself in the UI thread (one solution among others to do that would be to
create it when you start your application before starting the background
thread, store it as a member variable and then show this instance of the
dialog from your background thread).
Mar 16 '06 #2

Mehdi wrote:
On Thu, 16 Mar 2006 08:38:39 -0800, Todd wrote:
I've got a situation where I need to display a modal dialog from within a
background processing thread. The problem I'm having is that it needs to
display as a modal window to the thread's parent GUI app. When I try this I
get a pseudo-modal dialog (more like a top-level window)... the dialog is
always on top of the parent app's window, but the user can still access the
parent window and its controls.

Is there any way to accomplish true modal dialog functionality when opening
a dialog from within a separate thread?


Place the code showing the modal dialog in a function then marshall the
call of this function to the UI thread using the Invoke method of any
control that has been created in the UI thread. The result will be just
like if you had shown the modal dialog from the background thread and the
dialog will behave properly. You should also create the dialog object
itself in the UI thread (one solution among others to do that would be to
create it when you start your application before starting the background
thread, store it as a member variable and then show this instance of the
dialog from your background thread).


I'd go with the first option. The Show method, like most methods on a
form or control, has thread affinity requirements. In other words, it
must be called from the UI thread. The ISynchronizeInv oke methods
(Invoke, BeginInvoke, etc.) are exceptions.

Brian

Mar 16 '06 #3
Any way to tell the dialog created in the background thread to use the
foreground app's thread???

"Brian Gideon" wrote:

Mehdi wrote:
On Thu, 16 Mar 2006 08:38:39 -0800, Todd wrote:
I've got a situation where I need to display a modal dialog from within a
background processing thread. The problem I'm having is that it needs to
display as a modal window to the thread's parent GUI app. When I try this I
get a pseudo-modal dialog (more like a top-level window)... the dialog is
always on top of the parent app's window, but the user can still access the
parent window and its controls.

Is there any way to accomplish true modal dialog functionality when opening
a dialog from within a separate thread?


Place the code showing the modal dialog in a function then marshall the
call of this function to the UI thread using the Invoke method of any
control that has been created in the UI thread. The result will be just
like if you had shown the modal dialog from the background thread and the
dialog will behave properly. You should also create the dialog object
itself in the UI thread (one solution among others to do that would be to
create it when you start your application before starting the background
thread, store it as a member variable and then show this instance of the
dialog from your background thread).


I'd go with the first option. The Show method, like most methods on a
form or control, has thread affinity requirements. In other words, it
must be called from the UI thread. The ISynchronizeInv oke methods
(Invoke, BeginInvoke, etc.) are exceptions.

Brian

Mar 16 '06 #4
No. You must create the form on the UI thread. Likewise, you can only
access it from the UI thread. That is mandatory.

The following code snippet should help explain how this might be done.
I've omitted some stuff brevity, but I think you'll get the idea.

// .NET 1.1
public class YourBackgroundW orkerClass
{
// Get a reference to one of your app's forms here.
private Form mainForm;

private void YourBackgroundT hreadMethod()
{
// Do some stuff.

DisplayYourDial ogForm();

// Do some more stuff.
}

private void DisplayYourDial ogForm()
{
if (mainForm.Invok eRequired)
{
Delegate method = new ThreadStart(thi s.DisplayYourDi alogForm);
mainForm.Invoke (method, null);
}
else
{
YourDialogForm form = new YourDialogForm( );
form.ShowDialog ();
}
}
}

// .NET 2.0
public class YourBackgroundW orkerClass
{
// Get a reference to one of your app's forms here.
private Form mainForm;

private void YourBackgroundT hreadMethod()
{
// Do some stuff.

ThreadStart method = delegate()
{
YourDialogForm form = new YourDialogForm( );
form.ShowDialog ();
};

mainForm.Invoke (method, null);

// Do some more stuff.
}
}

Todd wrote:
Any way to tell the dialog created in the background thread to use the
foreground app's thread???

"Brian Gideon" wrote:


Mar 16 '06 #5

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

Similar topics

1
1324
by: Bart Nessux | last post by:
When testing scripts, I normally type 'ctrl' combined with the key 'c' to abort the script, however, this doesn't work with scripts that are threaded. What's the proper way to abort a threaded program?
8
2417
by: Matthew Bell | last post by:
Hi, I've got a question about whether there are any issues with directly calling attributes and/or methods of a threaded class instance. I wonder if someone could give me some advice on this. Generally, the documentation suggests that queues or similar constructs should be used for thread inter-process comms. I've had a lot of success in doing that (generally by passing in the queue during the __init__ of the thread) and I can see...
0
4933
by: Ganbold | last post by:
Hi, I'm new to multi-threaded programming and reading the book "Programming with POSIX Threads" and trying to understand concepts and coding. What I'm trying to do is to rewrite mysql client application (which calculates ISP dial-up customers' billing) into multi-threaded version.
2
3658
by: Michal Przytulski | last post by:
Hi, I'm looking information abouth runing PHP CLI application in multi-threaded - on http://www.php.net/manual/pl/ref.pcntl.php i found information abouth process control - but is PHP support multi-threaded ?? Can anyone help ??
2
2257
by: Chris | last post by:
I think I already know that the answer is that this can't be done, but I'll ask anyways. Suppose you want to use an RDBMS to store messages for a threaded message forum like usenet and then display the messages. A toy table definition (that I've tried to make standards compliant) might look like: create table messages ( message_id integer,
1
1985
by: Mullin Yu | last post by:
As subject. I have lots of VB6 dll and ocx files and they are single-threaded as VB6 doesn't support multi-threaded indeed. Can I wrap anything at .NET so that multi-threaded feature can be provided? Thanks! Mullin
6
4964
by: ben | last post by:
I am needing a web service to be single threaded. Is this possible? Any ideas would be helpful
3
2606
by: Rsrany | last post by:
I've been working on a few gtk applications and need to tie a hot key catcher into a thread. I am currently finding threaded user32.GetMessageA do not work. I have included two programs: 1) a non-threaded version that works 2) a threaded version that doesnt work. Any constructive suggestions would be helpful
14
2121
by: Snor | last post by:
I'm attempting to create a lobby & game server for a multiplayer game, and have hit a problem early on with the server design. I am stuck between using a threaded server, and using an event driven server. I've been told time and time again that I should use an event driven server design (that is, use twisted). There is a lot of interaction between the clients and they would often need to write to the same list of values, which of course...
14
3414
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
As far as I know, the C Standard has no mention of multi-threaded programming; it has no mention of how to achieve multi-threaded programming, nor does it mention whether the language or its libraries are suitable for multi-threaded programming. For people who are fond of portable C programming, what's the best way to go about multi-threaded programming? I've been reading up on POSIX threads a little, they seem pretty ubiquitous....
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9485
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
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, 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...
0
10161
jinu1996
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...
1
10098
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,...
0
9958
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 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...
1
7506
isladogs
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...
0
5390
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...
3
2890
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.