473,396 Members | 1,712 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.

MultiThreaded Form

Does anyone have any sample code for a multi threaded form that refreshes
itself while an extended operation is executing:

Example: I am updating a local dataset which could potentially have 1000's
of records. I would like to update a label in the meantime but the problem
is that the form seems to be locked while this operation is executing.

Any advice would be greatly appreciated.

Nov 15 '05 #1
5 5426
Look at the "Safe, Simple Multithreading in Windows Forms" series by Chris
Sells in MSDN.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Ken Saganowski" <ks*********@hillier.com> wrote in message
news:uo**************@TK2MSFTNGP11.phx.gbl...
Does anyone have any sample code for a multi threaded form that refreshes
itself while an extended operation is executing:

Example: I am updating a local dataset which could potentially have 1000's of records. I would like to update a label in the meantime but the problem is that the form seems to be locked while this operation is executing.

Any advice would be greatly appreciated.


Nov 15 '05 #2
"Ken Saganowski" <ks*********@hillier.com> wrote in message
news:uo**************@TK2MSFTNGP11.phx.gbl...
Does anyone have any sample code for a multi threaded form that refreshes
itself while an extended operation is executing:

Example: I am updating a local dataset which could potentially have 1000's of records. I would like to update a label in the meantime but the problem is that the form seems to be locked while this operation is executing.


Hi Ken,

You can't make calls back onto your UI thread from a secondary thread with
Windows Forms. Instead, need to use Control.Invoke, or one of a couple
other specialized commands that let you marshal the call back to the main UI
thread. Here's the first in a series of three articles that show you how to
do this and why you are having the problems you see now:

http://msdn.microsoft.com/library/de...ms06112002.asp

Joe
--
http://www.csharp-station.com
Nov 15 '05 #3
Thanks for the links. Articles contain needed information.

Ken
"Ken Saganowski" <ks*********@hillier.com> wrote in message
news:uo**************@TK2MSFTNGP11.phx.gbl...
Does anyone have any sample code for a multi threaded form that refreshes
itself while an extended operation is executing:

Example: I am updating a local dataset which could potentially have 1000's of records. I would like to update a label in the meantime but the problem is that the form seems to be locked while this operation is executing.

Any advice would be greatly appreciated.

Nov 15 '05 #4
Hi Ken,

I just posted some code to do this, see the thread Re: Progress bar without
GUI code in the model? a few post above your.

IF you have any doubt post back.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Ken Saganowski" <ks*********@hillier.com> wrote in message
news:uo**************@TK2MSFTNGP11.phx.gbl...
Does anyone have any sample code for a multi threaded form that refreshes
itself while an extended operation is executing:

Example: I am updating a local dataset which could potentially have 1000's of records. I would like to update a label in the meantime but the problem is that the form seems to be locked while this operation is executing.

Any advice would be greatly appreciated.

Nov 15 '05 #5
If you don't need interactivity, stay away from multithreading -- it isn't
necessary. Simply add a call to Refresh() after you update the label text:

Label label;
label.Text = "Processing record " + rec_num.ToString();
label.Refresh();

If you need interactivity w/ your user interface (e.g. you need to allow the
user to cancel the operation mid-stream), you either have to resort to running
the processing in a background thread (i.e. multithreaded) or occasionally
allow messages to be processed (not multi-threaded):
for (/* main processing loop*/)
{
// do one iteration of work

// process any pending messages
// Note: this uses the Win32 api, convert to .NET
while (PeekMessage(..., PM_REMOVE))
{
TranslateMessage(...);
DispatchMessage(...);
}

// break out if user pressed cancel
if (cancel_operation)
{
break;
}
}

Dig?
Ken Saganowski wrote:

Does anyone have any sample code for a multi threaded form that refreshes
itself while an extended operation is executing:

Example: I am updating a local dataset which could potentially have 1000's
of records. I would like to update a label in the meantime but the problem
is that the form seems to be locked while this operation is executing.

Any advice would be greatly appreciated.


--
Bret Pehrson
mailto:br**@infowest.com
NOSPAM - Include this key in all e-mail correspondence <<38952rglkwdsl>>
Nov 15 '05 #6

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

Similar topics

1
by: Elbert Lev | last post by:
I started with Python two weeks ago and already saved some time and efforts while writing 2 programs: 1. database extraction and backup tool, which runs once a month and creates a snapshot of...
2
by: pradyumna | last post by:
In Project settins - C/C++ - Code Generation, what is the difference between the option "Multithreaded" and "Multithreaded DLL". I understand that on selecting multithreaded option, single and...
6
by: Dan Kelley | last post by:
We have a multithreaded app that responds to events, and writes these events to a text file. This text file is used by an external system for further processing. We want to be able to write...
2
by: Ken Saganowski | last post by:
Has anyone ever created a multiThreaded form that constantly refreshes itself when doing tasks that take an extended period of time?
4
by: Richard Bell | last post by:
I'm new to VB.net and have a multithreaded application that needs to display a VB form with a cancel button. The thread that displays the form needs to set a cancel flag if the button is pressed. ...
3
by: groups | last post by:
Hi all, I've recently ported a rather large C application to run multithreaded. A few functions have seriously deteriorated in performance, in particular when accessing a rather large global...
1
by: Krupa | last post by:
Hi All, I am developing a multithreaded application in c# on vs 2005 (compact framework 2.0). I want to have a socket server in a background thread and want to continue with the windows form...
3
by: | last post by:
Is it possible to have just a multithreaded sub procedure? What I need is a timer time_elapsed event (2 sec interval) send params to a sub that is multithreaded. I have a COM component used to...
3
by: Jake K | last post by:
I have a multithreaded application that I now want to convert into a Windows Service. Does application.run work in a windows service? Are there things to take into consideration when creating 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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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.