.net - How to pass a Subroutine name as an argument for a function? -
i'm trying make generic function create threads, need pass subroutine name function, pass function name (which useless).
how can this?
there way without declaring delegate out of function? ...'cause said i'll make generic function simplify things.
this code:
public class form1 ' desired usage: ' make_thread(thread variable, thread name, thread priority, thread sub) ' ' example: ' make_thread(thread_1, "low thread", threading.threadpriority.low, addressof test_sub) private thread_1 threading.thread ' thread variable private function make_thread(of tkey)(byref thread_variable threading.thread, _ byval thread_name string, _ byval thread_priority threading.threadpriority, _ byref thread_sub func(of string, tkey)) boolean ' i'd byref function pass subroutine. ' see if thread running. dim is_running boolean if thread_variable nothing _ is_running = false _ else is_running = thread_variable.isalive ' if thread running, nothing. if is_running return false : exit function ' make thread. thread_variable = new threading.thread(addressof thread_sub) thread_variable.priority = thread_priority thread_variable.isbackground = true thread_variable.name = thread_name ' start thread. thread_variable.start() return true end function private sub test_sub() msgbox("a message thread!") end sub end class
Comments
Post a Comment