vb.net - How to write thread-safe methods? -


is practice , enough ensure thread-safety method dosomething in vb.net?

public class myform : inherits form      public sub dosomething(parameter object)         if me.invokerequired             me.invoke(sub() dosomething(parameter))         else             'do         end if     end sub  end class 

i believe may mean different thread-safety usual definition of term. normal meaning of term same method or object may called multiple threads simultaneously without errors or negative side effects. typically, kind of thread-safety accomplished via statelessness , locking (e.g. synclock).

however, in example, code not attempting provide kind of thread-safety, or @ least not directly. accomplish kind of thread-safety, forcing invocations executed on same single thread (the ui thread). winform applications (which presume is) require ui work done on ui thread. therefore, if method ui called thread, must first invoke ui thread before completing work. specific scenario, code have posted fine.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -