开发者

create objects at specific time with C#

开发者 https://www.devze.com 2023-03-08 02:07 出处:网络
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 afte

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;

0

精彩评论

暂无评论...
验证码 换一张
取 消