开发者

how to access a disposed object in a time-tick event?

OK, simply put i have a time ticker and after the end of the time tick 开发者_如何学编程event i dispose the code inside...however when the timeticker goes again...it cannot access the code within? So why a disposed object cannot be recreated? What do i have to do so each time a timetick event passes the object is used as it has to be and not simply overlooked?? 10x


according to your comments, I assume the code

timertickeven(whatever...) { 
    DisposableObject thiss = new DisposableObject(); 
    DisposableObject.Dispose(); 
}

is creating an DisposableObject (renamed by me, since object itself does not implement IDisposable), which implements the IDisposable interface. Every time the timer event is fired, such an object is created and afterwards disposed. Since the object is recreated every time, there is no connection to the object which were disposed at the last time, the event handler was executed. The solution therefore is, to get some sleep and watch the situation again tomorrow - with a fresh mind.

Besides: rethink about, if it would be possible to somehow pool those disposable objects. In general IDisposable is for resource consuming or very large objects. Having to recreate them frequently may deminish your execution performance.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜