create objects at specific time with C#
I want to write a program that create and delete objects of one class at specific time.
for example, one object from a class be created every 4 min and 30 seconds and then be remove at some time after.
How I can do开发者_开发问答 that?
Thanks guys...
It is possible to do it with a backgroundworker:
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += DoWork();
private void DoWork (object sender, DoWorkerEventArgs e)
{
bool stop = false;
while(!stop)
{
Thread.Sleep(someTime);
this.Object = new Object(); // Create your object the way you want.
stop = e.CancellationPending;
}
}
At this moment I can't test my code. Instead of a Thread.Sleep, you can use a ManualReset;
精彩评论