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

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.