473,396 Members | 2,089 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,396 software developers and data experts.

Can I create a .Net message loop without a Form?

When I have a long process to run I can create a new thread to run it and
create a modal dialog on my GUI thread. The modal dialog prevents any
messages (like button clicks) from working on my main Form. It also provides
a message loop, which allows paint messages and calls to the Control::Invoke
function to run. I can use these to invalidate an area and update it with
intermediate results of my process. When the process is done, I close the
modal dialog and everything works fine.

How can I do this, in .Net, without a modeless dialog?

I tried using Monitor to block the GUI thread. This prevents a message loop
from running. When I call Invoke from my process thread to invalidate an
area, it just hangs. It seems I will need a message loop. The only things I
can find to create a message loop are Application::Run and Form::ShowDialog.
The first throws an exception because I have already called it and the second
requires a modal dialog.
Jan 19 '06 #1
3 2221
Hi mccoyn!
When I have a long process to run I can create a new thread to run it and
create a modal dialog on my GUI thread. The modal dialog prevents any
messages (like button clicks) from working on my main Form. It also provides
a message loop, which allows paint messages and calls to the Control::Invoke
function to run. I can use these to invalidate an area and update it with
intermediate results of my process. When the process is done, I close the
modal dialog and everything works fine.


Application::DoEvents()

VC7/7.1:
http://msdn.microsoft.com/library/en...asp?frame=true

VC8:
http://msdn2.microsoft.com/system.wi....doevents.aspx

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Jan 19 '06 #2
Jochen, Thanks for the reply.

When I call Application::DoEvents it lets every event through. This doesn't
work well for my particular process as it would mean I have to add a check in
most the button events of my application to ignore them if the process is
running. When I use Form::ShowDialog it doesn't allow the events to get to
the parent window, except for a few like paint and invoke events, which are
the ones I want to get through.
"Jochen Kalmbach [MVP]" wrote:
Hi mccoyn!

Application::DoEvents()

VC7/7.1:
http://msdn.microsoft.com/library/en...asp?frame=true

VC8:
http://msdn2.microsoft.com/system.wi....doevents.aspx

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/

Jan 20 '06 #3
I was able to use the DoEvents function by disabling my application form.
This at least gets the behavior I want, but the form does an annoying flash
into disabled and right back to enabled when the process doesn't take a lot
of time. The other annoying thing is that DoEvents blocks when there are no
events. So, when my process is finished I have to send an event to get out
of DoEvents so my main thread can start running again and do things like
reenable the app.

I think I might try working with message filters to find another way.

"mccoyn" wrote:
Jochen, Thanks for the reply.

When I call Application::DoEvents it lets every event through. This doesn't
work well for my particular process as it would mean I have to add a check in
most the button events of my application to ignore them if the process is
running. When I use Form::ShowDialog it doesn't allow the events to get to
the parent window, except for a few like paint and invoke events, which are
the ones I want to get through.
"Jochen Kalmbach [MVP]" wrote:
Hi mccoyn!

Application::DoEvents()

VC7/7.1:
http://msdn.microsoft.com/library/en...asp?frame=true

VC8:
http://msdn2.microsoft.com/system.wi....doevents.aspx

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/

Jan 30 '06 #4

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

Similar topics

2
by: Nick | last post by:
Loop to create an array from a dynamic form. I'm having trouble with an application, and I'll try to explain it as clearly as possible: 1. I have a form with two fields, say Apples and...
5
by: me | last post by:
I have a Class Library that contains a Form and several helper classes. A thread gets created that performs processing of data behind the scenes and the Form never gets displayed (it is for debug...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
6
by: SamIAm | last post by:
Hi am creating a email application that needs to mail out a very large amount of emails. I have created a multithreaded c# application that using message queuing. I have created a threadpool of 5...
7
by: Roemer | last post by:
Hi all I stumbled over a new problem: I have a programm with just a class that is asynchronous listening for network connections. As soon as someone connected, a new form needs to be created....
27
by: max | last post by:
Hello, I am a newbye, and I'm trying to write a simple application. I have five tables with three columns; all tables are identical; I need to change some data in the first table and let VB...
8
by: chrisdavis | last post by:
I'm trying to filter by query or put those values in a distinct query in a where clause in some sort of list that it goes through but NOT at the same time. Example: ROW1 ROW2 ROW3 ROW4 ,...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
7
by: Matt | last post by:
Hi all, I'm trying to create a system where it reads a number of records from a database and then creates a row in the GUI that contains a single field from the database and a button that has a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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...
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
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.