Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am abstracting WPF: Dispatcher.BeginInvoke() behind an interface.

I want to provide a Task based version (for command line test, without UI) that run all BeginInvoke() in the same thread.
Would Task be appropriate to the task? How to make all run in the same thread?
Posted

"All BeginInvoke in the same thread" is absurd. BeginInvoke will always delegate your delegate parameter to be called to UI thread, and, if it is, by some weird reason, is itself called in the UI thread, it will work, but would make no practical sense, will only create one useless level of indirection.

Would Task be appropriate? Appropriate for what? It depends. If you explained some real goals someone or myself would probably advised you. But you specified some imaginary or maybe just poorly explained goal. Not any task. The idea of using one or another technique cannot be a goal. If you want to achieve something, you should better avoid mixing your questions with your ideas on how to achieve that. However, again, it depends.

To make the idea of invocation clear to you, please read my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

As to the custom task scheduler, it is rarely can be useful: https://msdn.microsoft.com/en-us/library/ee789351%28v=vs.110%29.aspx[^].

I really doubt that, even after your realize your real goals, it will help you. Again, it depends.

It really need deep understanding of the topic, to design your code properly using this approach.

—SA
 
Share this answer
 
v2
Comments
Super Lloyd 22-Apr-15 23:03pm    
So how does your answer relate in any way in UI less testing context?!?!?!?
Sergey Alexandrovich Kryukov 22-Apr-15 23:07pm    
I don't even know what is "UI less testing context". :-)
—SA
Super Lloyd 22-Apr-15 23:20pm    
Well... when your View Model is used in a console application NOT linked with ANY of the WPF libraries / DLLs
Sergey Alexandrovich Kryukov 23-Apr-15 0:50am    
All right, you did not even mention it in your question; so your question is not related to it.
—SA
Super Lloyd 23-Apr-15 1:38am    
Well, as per my question! ^_^ "I want to provide a Task based version (for command line test, without UI)"
Found a way!
Using LimitedConcurrencyLevelTaskScheduler class found on MSDN[^]!! :D
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900