Hi all,
I'm now trying to update a status indicator via a Timer control on a worker
thread. The status indicator is just a label on the main form, but I'm
having trouble figuring out exactly how to implement a separate worker
thread or asynchronous delegate that changes the label contents based on the
Timer control's ticks. Are there any good examples out there and can you
point me to one or two?
Thanks,
Michael C. 14 1451
It seems that the issue is that issuing SqlCommands on a SqlClient seems to
take over the current thread completely. I thought I could do this all on
the UI thread with a simple Timer control, but that ain't happenin'. Any
ideas on how I can get my Timer control to Tick during SqlCommand
executions? That would be a much simpler and preferable solution than a
separate thread. But I'm open to a separate worker thread if necessary.
Thanks in advance,
Michael C.
"Michael C" <mi*******@opto nline.net> wrote in message
news:y2******** **************@ news4.srv.hcvln y.cv.net... Hi all,
I'm now trying to update a status indicator via a Timer control on a
worker thread. The status indicator is just a label on the main form, but I'm having trouble figuring out exactly how to implement a separate worker thread or asynchronous delegate that changes the label contents based on
the Timer control's ticks. Are there any good examples out there and can you point me to one or two?
Thanks, Michael C.
Hi Michael,
See this fine article (there are 3 parts)
Safe, Simple Multithreading in Windows Forms http://msdn.microsoft.com/library/de...ms06112002.asp
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com www.rthand.com
"Michael C" <mi*******@opto nline.net> wrote in message
news:y2******** **************@ news4.srv.hcvln y.cv.net... Hi all,
I'm now trying to update a status indicator via a Timer control on a
worker thread. The status indicator is just a label on the main form, but I'm having trouble figuring out exactly how to implement a separate worker thread or asynchronous delegate that changes the label contents based on
the Timer control's ticks. Are there any good examples out there and can you point me to one or two?
Thanks, Michael C.
Thanks for the link. He has the same example code in his book (Windows
Forms Programming in C#). Problem is that it doesn't solve my real problem,
which is that the SQL Query I'm executing seems to block the Timer() control
Tick event from ever executing. Even when I run the status update code on a
separate thread like in his book... How can I make my Timer() Tick like
it's supposed to?
Thanks,
Michael C.
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:up******** ******@tk2msftn gp13.phx.gbl... Hi Michael,
See this fine article (there are 3 parts) Safe, Simple Multithreading in Windows Forms http://msdn.microsoft.com/library/de...ms06112002.asp -- Miha Markic [MVP C#] - RightHand .NET consulting & development miha at rthand com www.rthand.com
"Michael C" <mi*******@opto nline.net> wrote in message news:y2******** **************@ news4.srv.hcvln y.cv.net... Hi all,
I'm now trying to update a status indicator via a Timer control on a worker thread. The status indicator is just a label on the main form, but I'm having trouble figuring out exactly how to implement a separate worker thread or asynchronous delegate that changes the label contents based on the Timer control's ticks. Are there any good examples out there and can
you point me to one or two?
Thanks, Michael C.
....P.S. I've even tried running my SQL Queries using asynchronous delegates
and setting the status updates code on it's own thread... I'm pretty much
lost as to what else I can possibly do to make this work...
Thanks,
Michael C.
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:up******** ******@tk2msftn gp13.phx.gbl... Hi Michael,
See this fine article (there are 3 parts) Safe, Simple Multithreading in Windows Forms http://msdn.microsoft.com/library/de...ms06112002.asp -- Miha Markic [MVP C#] - RightHand .NET consulting & development miha at rthand com www.rthand.com
"Michael C" <mi*******@opto nline.net> wrote in message news:y2******** **************@ news4.srv.hcvln y.cv.net... Hi all,
I'm now trying to update a status indicator via a Timer control on a worker thread. The status indicator is just a label on the main form, but I'm having trouble figuring out exactly how to implement a separate worker thread or asynchronous delegate that changes the label contents based on the Timer control's ticks. Are there any good examples out there and can
you point me to one or two?
Thanks, Michael C.
Any timers added in the UI (through the Timer control) require that the
message queue is being pumped in the UI thread for the timer to execute. If
you have executed a synchronous procedure on the UI thread, then the UI
thread will be blocked until the function returns and the timer will not
execute.
You might find that it's better to execute the sqlcommand on a worker thread
(the easiest way is through the thread pool), leaving you free to update the
UI while the sqlcommand is being executed.
--
John Wood
EMail: first name, dot, second name at priorganize.com
"Michael C" <mi*******@opto nline.net> wrote in message
news:g_******** **************@ news4.srv.hcvln y.cv.net... Thanks for the link. He has the same example code in his book (Windows Forms Programming in C#). Problem is that it doesn't solve my real
problem, which is that the SQL Query I'm executing seems to block the Timer()
control Tick event from ever executing. Even when I run the status update code on
a separate thread like in his book... How can I make my Timer() Tick like it's supposed to?
Thanks, Michael C.
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:up******** ******@tk2msftn gp13.phx.gbl... Hi Michael,
See this fine article (there are 3 parts) Safe, Simple Multithreading in Windows Forms http://msdn.microsoft.com/library/de...ms06112002.asp -- Miha Markic [MVP C#] - RightHand .NET consulting & development miha at rthand com www.rthand.com
"Michael C" <mi*******@opto nline.net> wrote in message news:y2******** **************@ news4.srv.hcvln y.cv.net... Hi all,
I'm now trying to update a status indicator via a Timer control on a worker thread. The status indicator is just a label on the main form, but
I'm having trouble figuring out exactly how to implement a separate worker thread or asynchronous delegate that changes the label contents based
on the Timer control's ticks. Are there any good examples out there and can you point me to one or two?
Thanks, Michael C.
Yeah I have a 'not-so-elegant' solution I'm playing with now. I had to use
a Timer from the System.Timers namespace as opposed to the Windows.Forms
timer and then execute the SQL Queries in asynchronous delegates using
callbacks. You'd think there'd be an easier way. I'm sure there's a better
way. It's amazing that something so simple could be so complicated to
implement.
Thanks,
Michael C.
"John Wood" <sp**@isannoyin g.com> wrote in message
news:uL******** ******@tk2msftn gp13.phx.gbl... Any timers added in the UI (through the Timer control) require that the message queue is being pumped in the UI thread for the timer to execute.
If you have executed a synchronous procedure on the UI thread, then the UI thread will be blocked until the function returns and the timer will not execute.
You might find that it's better to execute the sqlcommand on a worker
thread (the easiest way is through the thread pool), leaving you free to update
the UI while the sqlcommand is being executed.
-- John Wood EMail: first name, dot, second name at priorganize.com
"Michael C" <mi*******@opto nline.net> wrote in message news:g_******** **************@ news4.srv.hcvln y.cv.net... Thanks for the link. He has the same example code in his book (Windows Forms Programming in C#). Problem is that it doesn't solve my real problem, which is that the SQL Query I'm executing seems to block the Timer() control Tick event from ever executing. Even when I run the status update code
on a separate thread like in his book... How can I make my Timer() Tick like it's supposed to?
Thanks, Michael C.
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:up******** ******@tk2msftn gp13.phx.gbl... Hi Michael,
See this fine article (there are 3 parts) Safe, Simple Multithreading in Windows Forms http://msdn.microsoft.com/library/de...ms06112002.asp -- Miha Markic [MVP C#] - RightHand .NET consulting & development miha at rthand com www.rthand.com
"Michael C" <mi*******@opto nline.net> wrote in message news:y2******** **************@ news4.srv.hcvln y.cv.net... > Hi all, > > I'm now trying to update a status indicator via a Timer control on a worker > thread. The status indicator is just a label on the main form, but I'm > having trouble figuring out exactly how to implement a separate
worker > thread or asynchronous delegate that changes the label contents
based on the > Timer control's ticks. Are there any good examples out there and
can you > point me to one or two? > > Thanks, > Michael C. > >
Yeah you would think it would be easier I know. ADO.Net isn't exactly the
holy grail it's often made out to be.
Keep in mind that so-called 'asynchronous delegates' may be asynchronous,
but they simply execute on a temporary worker thread taken from the thread
pool. There 2 problems with this. Firstly, the thread pool has a limit of 64
threads, if more than that are in use, the operation will be queued until a
thread slot is availble. Secondly, it's unnecessary -- these sql operations
are asynchronous in nature (ie. they send data over sockets, and then wait
for the response from the server). It's unnecessary to have a thread
dedicated to waiting for the data to come back when it could just have the
socket send a message to the UI when the data is available. All of the async
mechanisms in .net use the thread-pool, even web-requests. All seems a bit
silly if you ask me.
--
John Wood
EMail: first name, dot, second name at priorganize.com
"Michael C" <mi*******@opto nline.net> wrote in message
news:q_******** **************@ news4.srv.hcvln y.cv.net... Yeah I have a 'not-so-elegant' solution I'm playing with now. I had to
use a Timer from the System.Timers namespace as opposed to the Windows.Forms timer and then execute the SQL Queries in asynchronous delegates using callbacks. You'd think there'd be an easier way. I'm sure there's a
better way. It's amazing that something so simple could be so complicated to implement.
Thanks, Michael C.
"John Wood" <sp**@isannoyin g.com> wrote in message news:uL******** ******@tk2msftn gp13.phx.gbl... Any timers added in the UI (through the Timer control) require that the message queue is being pumped in the UI thread for the timer to execute. If you have executed a synchronous procedure on the UI thread, then the UI thread will be blocked until the function returns and the timer will not execute.
You might find that it's better to execute the sqlcommand on a worker thread (the easiest way is through the thread pool), leaving you free to update the UI while the sqlcommand is being executed.
-- John Wood EMail: first name, dot, second name at priorganize.com
"Michael C" <mi*******@opto nline.net> wrote in message news:g_******** **************@ news4.srv.hcvln y.cv.net... Thanks for the link. He has the same example code in his book
(Windows Forms Programming in C#). Problem is that it doesn't solve my real problem, which is that the SQL Query I'm executing seems to block the Timer() control Tick event from ever executing. Even when I run the status update
code on a separate thread like in his book... How can I make my Timer() Tick
like it's supposed to?
Thanks, Michael C.
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:up******** ******@tk2msftn gp13.phx.gbl... > Hi Michael, > > See this fine article (there are 3 parts) > Safe, Simple Multithreading in Windows Forms > http://msdn.microsoft.com/library/de...ms06112002.asp > > -- > Miha Markic [MVP C#] - RightHand .NET consulting & development > miha at rthand com > www.rthand.com > > "Michael C" <mi*******@opto nline.net> wrote in message > news:y2******** **************@ news4.srv.hcvln y.cv.net... > > Hi all, > > > > I'm now trying to update a status indicator via a Timer control on
a > worker > > thread. The status indicator is just a label on the main form,
but I'm > > having trouble figuring out exactly how to implement a separate worker > > thread or asynchronous delegate that changes the label contents based on > the > > Timer control's ticks. Are there any good examples out there and can you > > point me to one or two? > > > > Thanks, > > Michael C. > > > > > >
I am a little disappointed that there's no built-in simple (50 words or
less) way to update the UI from a worker thread. I would think this would
be a very common problem that programmers run up against all the time. As
for the SQL operations running asynchronously, for whatever reason (maybe
because I'm running them on a local SQL Server??) the SqlCommands I'm
sending are completely blocking the Windows Forms.Timer() control. I've
verified that it doesn't Tick at all until the SqlCommand has finished
executing. I thought the SqlCommands ran asynchronously also, but it
doesn't look like it; or maybe there's an asynchronous option on the
SqlCommand I'm missing? As far as the limits on the thread pool, that
shouldn't be a problem. The only two things I'm doing at any one time are:
1) running one SqlCommand at a time and 2) updating the status on the UI.
Other than that, all other processing occurs in the UI thread.
Thanks for the help!
Michael C.
"John Wood" <sp**@isannoyin g.com> wrote in message
news:O5******** ******@tk2msftn gp13.phx.gbl... Yeah you would think it would be easier I know. ADO.Net isn't exactly the holy grail it's often made out to be.
Keep in mind that so-called 'asynchronous delegates' may be asynchronous, but they simply execute on a temporary worker thread taken from the thread pool. There 2 problems with this. Firstly, the thread pool has a limit of
64 threads, if more than that are in use, the operation will be queued until
a thread slot is availble. Secondly, it's unnecessary -- these sql
operations are asynchronous in nature (ie. they send data over sockets, and then wait for the response from the server). It's unnecessary to have a thread dedicated to waiting for the data to come back when it could just have the socket send a message to the UI when the data is available. All of the
async mechanisms in .net use the thread-pool, even web-requests. All seems a bit silly if you ask me.
-- John Wood EMail: first name, dot, second name at priorganize.com
"Michael C" <mi*******@opto nline.net> wrote in message
news:g_******** **************@ news4.srv.hcvln y.cv.net... Thanks for the link. He has the same example code in his book (Windows Forms Programming in C#). Problem is that it doesn't solve my real
problem, which is that the SQL Query I'm executing seems to block the Timer()
control Tick event from ever executing. Even when I run the status update code on
a separate thread like in his book... How can I make my Timer() Tick like it's supposed to?
If your seperate thread is not responding to Timer events (or any other),
run the thread continuously in a loop and use Thread.Sleep() so as to not
consume the processor.
Norvin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kamus of Kadizhar |
last post by:
I have the following function which generates MD5 hashes for files on a
local and remote server. The remote server has a little applet that
runs from inetd and generates an MD5 hash given the file name.
The problem is that it takes 2+ minutes to generate the MD5 hash, so
this function takes about 5 minutes every time it is called. Since the
first MD5 hash is generated on a remote machine, the local machine does
nothing but wait for...
|
by: Ronan Viernes |
last post by:
Hi,
I have created a python script (see below) to count the maximum number
of threads per process (by starting new threads continuously until it
breaks).
######
#testThread.py
import thread, sys
|
by: Al Tobey |
last post by:
I was building perl 5.8.2 on RedHat Enterprise Linux 3.0 (AS) today and
noticed that it included in it's ccflags "-DTHREADS_HAVE_PIDS." I am
building with -Dusethreads. With newer Linux distributions using the
Native Posix Threading Layer (NPTL), this isn't entirely true anymore and
is AFAIK unsupported (using a pid to signal/identify threads). I removed
it from my config.sh script and ran Configure -der. make test runs just
fine.
...
|
by: Bengt Richter |
last post by:
It seems lately all my posts have been coming back to me as bounced emails,
and I haven't emailed them ;-(
I've been getting bounce messages like (excerpt):
....
_______________________________________________
This is the Postfix program at host deimos.liage.net.
I'm sorry to have to inform you that your message could not be
|
by: Darian |
last post by:
Is there a way to find all the thread names that are running in a
project?
For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and
T5 are running...I want to be able to know that T2, T4 and T5 are
already running.
Thanks,
Darian
| |
by: Joe Van Dyk |
last post by:
I've been using Ruby for the past couple years. But fate has decided that
I return to C++ for the time being.
Unfortunately, I've forgotten a lot of C++. So, here's my training
regime. I need to get up to speed on C++, networking, threads, XML (and
hopefully unit testing -- never done automated tests with C++).
- Accelerated C++
- Programming with POSIX Threads
- C++ Coding Standards
|
by: Tammy |
last post by:
Hello -
I have read many threads regarding back-end security and have found
them all useful. I have a couple of (what seem to be basic) questions:
I have a secured front-end and back-end database. (I did use the
security wizard for this.) By using the shortcuts provided, both files
require a password to get in.
Here is the problem: if I try to access the front-end through Windows
|
by: =?Utf-8?B?RkxEYXZlTQ==?= |
last post by:
I'm developing an application that gets data from 100 sources (via telnet
connections, but you can think stock quotes from a webservice if you like).
I was planning on using the thread pool (25 at a time). I know I would start
all 100 at once and as threads finish, a new thread would become available
and the next one would start.
However, I need to do this over and over (using an app that will run for
days or longer). How can I tell...
|
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= |
last post by:
I started out with C++ about 8 years ago, but in the last two years or
so I switched to doing a lot of C programming, so I've been out of the
loop for a while.
Anyway I've a few quick questions to ask:
Currently what's the biggest integer type in C++? Does C++ have all
the <stdint.htypes such as uint_fast64_t? I use these types a lot.
Back when I did C++ programming a few years ago, I don't think all C++
implementations were...
|
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...
|
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,...
| |
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: 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: 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: 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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |