473,793 Members | 2,922 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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::Ru n and Form::ShowDialo g.
The first throws an exception because I have already called it and the second
requires a modal dialog.
Jan 19 '06 #1
3 2246
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::Do Events()

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::Do Events 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::ShowDialo g 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::Do Events()

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::Do Events 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::ShowDialo g 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::Do Events()

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
4082
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 Oranges. The user selects from a drop down menu, between 1-10 of each and clicks submit. The resulting page will display a NEW form, with rows and a list of fields for the amount of each items selected.
5
3641
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 puposes only and is not normally visable to the user.) The Thread function is actually in the Form class. Now.. What I am seeing is that when I create an instance of this Class Library's Form, which starts the worker thread, it seems to hose up...
7
8873
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 want my users to be able to select a report, click on a command button on a form, which will then automatically create the report as a pdf file and save it to the user's machine. I am using Adobe Acrobat (5.0 I think) and have Adobe Distiller as a
6
3320
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 threads and each thread checks the queue, receives the message and sends an email. How do I determine the right amount of threads to create? Thanks, S
7
3243
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. The Form gets created but hangs after creation. I'ts logical that that happens because the new Form doesn't get a Message Loop. The Message Loop is created on Application.Run() on the Main Method on the Main Thread. The Callback is (normally)...
27
3798
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 updates the same data in all other four tables in the right places. I know it would be possible by using the ForeignKeyConstraint object. I have created the tables using the DataSet Visual Tool and I know it doesn't create any ForeignKeyConstraint obj....
8
3482
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 , etc. I want to go to the first row, do a WHERE statement, return the
4
12444
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 this: can Access create the document and place it as an OLE object to the relevant table? Any help is greatly appreciated. Ricky
7
11360
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 reference to the record. This way, once the task has been accomplished, the button can be pressed next to the field and a time-stamp is placed into the database. Can anyone point me in the direction of either a tutorial or
0
9671
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
9518
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
10212
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...
0
10000
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...
0
9035
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, 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...
1
7538
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
6777
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();...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4112
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.