开发者

Similar to Control.Invoke for my custom class

If i want to create a class ( just for testing and understanding purpose) that should behave like a control in a sense that when开发者_如何学编程ever i try to do cross-thread access, I should be able to throw an exception. how do i implement in .NET C#. ( Dont Derive from control class. The similarity ends with respect to cross-thread access)

For example I have a class Employee, when somebody access the object from other than the thread created, I need to behave like control and throw an exception? Pls Help


You could save the value of the Thread.CurrentThread.ManagedThreadId in the constructor, and then compare the thread id when a function is called with the stored value? If they are different throw an exception.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜