0

I want to run a function just for specific time (say 10 min). After specific time it will return successful if it is able to execute the function successfully or unsuccessful.
The function does a large amount of data processing and updating the tables.
I want to stop executing that function after 10 min. If successful then its fine. If not i need to rollback the transaction which is after thought.

I am using asp.net with C#.

So is there any way i can stop execution of a function after specific time?

Any ideas would be really appreciated.

Thanks

2
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by chintan_1671
0

That can be done using threading, which indeed is a very deep topic but basically you can do this.

System.Threading.Thread tre =  new System.Threading.Thread(new ThreadStart(MyFunction));
tre.Start();
System.Threading.Thread.Sleep(10000);
if (tre.IsAlive)
   tre.Abort();

//The you have your function
void MyFunction()
{
   //Do process
}

There is a lot of things you can do with thread, delegates, async calls etc, read about it. hope that help you to go and the right direction

0

Thanks a lot .. it solved my problem ...

I have 1 more thing .. is there any way that i can display time of thread sleep .. May be from 0:00 or count down time of thread sleep on display ?

Please let me know.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.