473,795 Members | 2,919 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re-running an already created thread.

Hi,
I am running a separate thread in order to be able to poll devices on a
MODBUS RTU network. I create a thread and look at the ThreadObj.IsAli ve
flag, and this work ok. I then might have to come back later to the
thread an re run the task contained within it. When I come to re-run
the thread, when I call to ThreadObj.Start it throws an exception.
Ordinarily in C++ I would delete the ThreadObj and then re-create one
with the oThread = new Thread(new ThreadStart(Sea rchThread)); call.
Seeing as I cannot do my own garbage collection when I need to wondered
if anyone had any comments?

Most of my experience is C++/MFC and am now porting a current app to C#
in order to better my understanding of the langauge.
Thanks,

Rob.
Nov 16 '05 #1
2 2353
Robert,

You will have to recreate the thread exactly as you indicated. Though,
you should make sure that the original thread is not running first.
Take a look at the following multipage article on multithreading in
..NET for tips on working with threads. The article is an excellent
resource that is frequently cited in this group.

<http://www.yoda.arachs ys.com/csharp/threads/>

Also, there may be better design patterns for executing this task. One
alternative that comes to mind is to create a thread that is dedicated
to executing the task. This thread will sit idle in an infinite loop
waiting for an event (AutoResetEvent or ManualResetEven t) to be
signaled that instructs the thread to begin executing the task. If the
task completes quickly the ThreadPool may be a better approach. It's
difficult to say for sure which one is better without knowing what the
task does.

Brian

Robert Wilson wrote:
Hi,
I am running a separate thread in order to be able to poll devices on
a MODBUS RTU network. I create a thread and look at the
ThreadObj.IsAli ve flag, and this work ok. I then might have to come
back later to the thread an re run the task contained within it.
When I come to re-run the thread, when I call to ThreadObj.Start it
throws an exception. Ordinarily in C++ I would delete the ThreadObj
and then re-create one with the oThread = new
Thread(new ThreadStart(Sea rchThread)); call. Seeing as I cannot do my
own garbage collection when I need to wondered if anyone had any
comments?

Most of my experience is C++/MFC and am now porting a current app to
C# in order to better my understanding of the langauge.
Thanks,

Rob.


Nov 16 '05 #2
Brian Gideon wrote:
Robert,

You will have to recreate the thread exactly as you indicated. Though,
you should make sure that the original thread is not running first.
Take a look at the following multipage article on multithreading in
.NET for tips on working with threads. The article is an excellent
resource that is frequently cited in this group.

<http://www.yoda.arachs ys.com/csharp/threads/>

Also, there may be better design patterns for executing this task. One
alternative that comes to mind is to create a thread that is dedicated
to executing the task. This thread will sit idle in an infinite loop
waiting for an event (AutoResetEvent or ManualResetEven t) to be
signaled that instructs the thread to begin executing the task. If the
task completes quickly the ThreadPool may be a better approach. It's
difficult to say for sure which one is better without knowing what the
task does.

Brian

Robert Wilson wrote:
Hi,
I am running a separate thread in order to be able to poll devices on
a MODBUS RTU network. I create a thread and look at the
ThreadObj.IsA live flag, and this work ok. I then might have to come
back later to the thread an re run the task contained within it.
When I come to re-run the thread, when I call to ThreadObj.Start it
throws an exception. Ordinarily in C++ I would delete the ThreadObj
and then re-create one with the oThread = new
Thread(new ThreadStart(Sea rchThread)); call. Seeing as I cannot do my
own garbage collection when I need to wondered if anyone had any
comments?

Most of my experience is C++/MFC and am now porting a current app to
C# in order to better my understanding of the langauge.
Thanks,

Rob.


Thanks a lot Brian. Looks like i'm on my way now.

Regards,

Rob.
Nov 16 '05 #3

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

Similar topics

1
4324
by: Nel | last post by:
I have a question related to the "security" issues posed by Globals ON. It is good programming technique IMO to initialise variables, even if it's just $foo = 0; $bar = ""; Surely it would be better to promote better programming than rely on PHP to compensate for lazy programming?
4
6430
by: Craig Bailey | last post by:
Anyone recommend a good script editor for Mac OS X? Just finished a 4-day PHP class in front of a Windows machine, and liked the editor we used. Don't recall the name, but it gave line numbers as well as some color coding, etc. Having trouble finding the same in an editor that'll run on OS X. -- Floydian Slip(tm) - "Broadcasting from the dark side of the moon"
1
4101
by: Chris | last post by:
Sorry to post so much code all at once but I'm banging my head against the wall trying to get this to work! Does anyone have any idea where I'm going wrong? Thanks in advance and sorry again for adding so much code... <TABLE border="1" bordercolor="#000000" cellspacing="0"> <TR>
11
4012
by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
1
3705
by: John Ryan | last post by:
What PHP code would I use to check if submitted sites to my directory actually exist?? I want to use something that can return the server code to me, ie HTTP 300 OK, or whatever. Can I do this with sockets??
10
4226
by: James | last post by:
What is the best method for creating a Web Page that uses both PHP and HTML ? <HTML> BLA BLA BLA BLA BLA
8
4420
by: Beowulf | last post by:
Hi Guru's, I have a query regarding using PHP to maintain a user profiles list. I want to be able to have a form where users can fill in their profile info (Name, hobbies etc) and attach an image, which will upload the record to a mySql db so users can then either view all profiles or query.. I.e. show all males in UK, all femails over 35 etc. Now, I'm not asking for How to do this but more what would be the best way? I've looked at...
3
3492
by: presspley | last post by:
I have bought the book on advanced dreamweaver and PHP recently. I have installed MySQL and PHP server but am getting an error on the $GET statement show below. It says there is a problem with the variable $GET but $GET is not a variable, I thought it came from the page that calls the PHP file? if(($_GET)==""){ this gets an error
2
106620
by: sky2070 | last post by:
i have two file with jobapp.html calling jobapp_action.php <HTML> <!-- jobapp.html --> <BODY> <H1>Phop's Bicycles Job Application</H1> <P>Are you looking for an exciting career in the world of cyclery? Look no further! </P> <FORM NAME='frmJobApp' METHOD=post ACTION="jobapp_action.php"> Please enter your name:
1
13661
by: Brian | last post by:
I have an array like this: $events = array( array( '2003-07-01', 'Event Title 1', '1' //ID Number (not unique) ), array( '2003-07-02',
0
9673
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
10443
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
10216
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
10165
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
10002
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
9044
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...
0
6783
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
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.