473,804 Members | 3,029 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting the lifespan of a thread

Hi all,

Is there a way to set the lifespan of a thread.

I am trying to start a process that may or may not have an outcome and want
to finish it after a certain length of time finished or not.

So I have

Thread t = new Thread(new ThreadStart(tar getMethod));
t.start();

how can I terminate t after a length of time I decide?

Thanks
Nick
Nov 15 '05 #1
4 1835
Hi Nicholas,

Perhaps Thread.Abort() method might help you?

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

"Nicholas Beenham" <ni**********@b lueyonder.co.uk > wrote in message
news:Oq******** ******@TK2MSFTN GP10.phx.gbl...
Hi all,

Is there a way to set the lifespan of a thread.

I am trying to start a process that may or may not have an outcome and want to finish it after a certain length of time finished or not.

So I have

Thread t = new Thread(new ThreadStart(tar getMethod));
t.start();

how can I terminate t after a length of time I decide?

Thanks
Nick

Nov 15 '05 #2
So would I use a timer then call abort?

"Miha Markic" <miha at rthand com> wrote in message
news:u8******** ******@TK2MSFTN GP12.phx.gbl...
Hi Nicholas,

Perhaps Thread.Abort() method might help you?

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

"Nicholas Beenham" <ni**********@b lueyonder.co.uk > wrote in message
news:Oq******** ******@TK2MSFTN GP10.phx.gbl...
Hi all,

Is there a way to set the lifespan of a thread.

I am trying to start a process that may or may not have an outcome and

want
to finish it after a certain length of time finished or not.

So I have

Thread t = new Thread(new ThreadStart(tar getMethod));
t.start();

how can I terminate t after a length of time I decide?

Thanks
Nick


Nov 15 '05 #3
How about using Join(timeSpan). If you don't want to block the calling
thread, have it start a "joiner thread" that itself starts your worker
thread and then calls Join on it.

The "joiner thread" would call Abort on the worker thread when it gets
control, if the latter has not yet finished.
"Nicholas Beenham" <ni**********@b lueyonder.co.uk > wrote in message
news:Oq******** ******@TK2MSFTN GP10.phx.gbl...
Hi all,

Is there a way to set the lifespan of a thread.

I am trying to start a process that may or may not have an outcome and want to finish it after a certain length of time finished or not.

So I have

Thread t = new Thread(new ThreadStart(tar getMethod));
t.start();

how can I terminate t after a length of time I decide?

Thanks
Nick

Nov 15 '05 #4
Hi,

"Nicholas Beenham" <ni**********@b lueyonder.co.uk > wrote in message
news:uL******** ******@TK2MSFTN GP09.phx.gbl...
So would I use a timer then call abort?


Yes, or the solution Fred suggested.
You might even spawn another thread which does the "dirty" job :)

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
Nov 15 '05 #5

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

Similar topics

4
1958
by: abCSharp | last post by:
I understand that static variables have app-domain scope. Till the app-domain is in memory, the static variable will be in memory. When are the app-domains unloaded is the question. I have read somewhere in this forum that statics live till the asp.net process is recycled. Please clarify if someone can. Thanx! "David Jessee" wrote: > I'd be VERY careful about using a shared page member for state management. > its true that there is...
3
1954
by: Patrick | last post by:
I am dynamically creating TextArea and drop-down lists in ASP.NET using something like HtmlTextArea eachTextArea = new HtmlTextArea(); I tried to set the "name" of these TextAreas, etc. (e.g. <textarea name="NameOfTextArea" rows="5" cols="60">some text area</textarea>), as I want to then dynamically read back the controls' values Setting the ID attributes doesn't work, nor does the following:...
1
1375
by: Roland Müller | last post by:
Hello, we have converted our project to framework 2.0 but we have still some problems, one of it with setting the UICulture for a aspx-site. Example: there is a simple aspx test site in a solution with two resx files in the App_GlobalResources folder: - ffTest.en.resx - ffTest.resx
4
6463
by: Vlad Dogaru | last post by:
Hello, I am trying to use cookies and Python to create a simple login example. But I am very disoriented at the existence of two cookie libraries, namely Cookie and cookielib. I have seen examples of setting cookies (although I am still not sure about timestamps and cookie lifespan), but no reference to getting the currently set cookies. For instance, I want to see if there is any 'user' value, to check whether the user has logged in....
7
6188
by: Academic | last post by:
What are the different effects of the following two statements: C1.Cursor = Cursors.WaitCursor C1.Cursor.Current = Cursors.WaitCursor I believe the first replaces the entire C1.Cursor object with a new one while the second only replaces the Current object of C1.Cursor, but I can't
12
5014
by: info | last post by:
Hi All, I am trying to set the hourglass cursor inside a class that has nothing to do with MainForm class and I don't want to pass a reference to MainForm. How can I set the current cursor to Hourglass and then back to arrow? Thanks a lot,
0
2301
by: kidders | last post by:
Seem to be having problems with the en-GB culture/uiCulture setting, its making dates a format of the incorrect MM/dd/yyyy. I've searched the groups on this issue, here is a lengthy thread, where i have tried every thing stated: *registry settings *regional language settings *page level and app level culture/uiCulture settings...
4
1957
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post by:
Hi; When a Page object - the code-behind of an aspx page is created - what is the lifespan of that created object? Is it tied to the session, the request/response, or is it in a poll and reused for the next request/response to that page from any session? -- thanks - dave david_at_windward_dot_net
1
3460
by: nicerun | last post by:
I'm using the Application_Start event at Global.asax.cs to invoke thread that do some job. I know that Application_Start event occurs when the very first request to Web Application received. - Setting worker process count 1. Start | Programs | Administrative Tools | Internet Information Services 2. Right-click on the application pool, e.g. ‘DefaultAppPool’, and select ‘Properties’
0
10571
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...
1
10317
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
10075
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...
1
7615
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
6851
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
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
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
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.