dispatcher

Application Dispatcher and Control Dispatcher

会有一股神秘感。 提交于 2019-12-01 06:53:37
问题 Assume i have control button with name "button1" and function with name "doSomething". Function "doSomething" is called from another thread. i have two method to call function doSomething from UI thread. First, from control button dispatcher this.button1.Dispatcher.BeginInvoke(new Action(() => { doSomething(); })); and Second, from application dispatcher this.Dispatcher.BeginInvoke(new Action(() => { doSomething(); })); The result is same, what is the real different ? 回答1: The same dispatcher

深入理解Cglib动态代理及手动实现

六眼飞鱼酱① 提交于 2019-12-01 06:19:33
CGLIB介绍与原理(部分节选自网络) 一、什么是CGLIB? CGLIB是一个功能强大,高性能的代码生成包。它为没有实现接口的类提供代理,为JDK的动态代理提供了很好的补充。通常可以使用Java的动态代理创建代理,但当要代理的类没有实现接口或者为了更好的性能,CGLIB是一个好的选择。 二、CGLIB原理 CGLIB原理:动态生成一个要代理类的子类,子类重写要代理的类的所有不是final的方法。在子类中采用方法拦截的技术拦截所有父类方法的调用,顺势织入横切逻辑。它比使用java反射的JDK动态代理要快。 CGLIB底层:使用字节码处理框架ASM,来转换字节码并生成新的类。不鼓励直接使用ASM,因为它要求你必须对JVM内部结构包括class文件的格式和指令集都很熟悉。 CGLIB缺点 :对于final方法,无法进行代理。 三、CGLIB的应用 广泛的被许多AOP的框架使用,例如Spring AOP和dynaop。Hibernate使用CGLIB来代理单端single-ended(多对一和一对一)关联。 四、CGLIB的API 1、Jar包 : cglib-nodep-2.2.jar:使用nodep包不需要关联asm的jar包,jar包内部包含asm的类. cglib-2.2.jar:使用此jar包需要关联asm的jar包,否则运行时报错. 2、CGLIB类库: 由于基本代码很少

My async Task always blocks UI

余生颓废 提交于 2019-11-30 17:47:01
In a WPF 4.5 application, I don't understand why the UI is blocked when I used await + a task : private async void Button_Click(object sender, RoutedEventArgs e) { // Task.Delay works great //await Task.Delay(5000); double value = await JobAsync(25.0); MessageBox.Show("finished : " + value.ToString()); } private async Task<double> JobAsync(double value) { for (int i = 0; i < 30000000; i++) value += Math.Log(Math.Sqrt(Math.Pow(value, 0.75))); return value; } The await Task.Delay works great, but the await JobAsync blocks the UI. Why ? Thank you. Try this: private Task<double> JobAsync(double

How to access separate thread generated WPF UI elements from the Dispatcher thread?

送分小仙女□ 提交于 2019-11-30 15:45:38
问题 I need to generate a print preview (a long one) using wpf UI elements like FixedDocument, FlowDocument, PageContent, BlockUIContainer and all those. To keep my UI responsive i'm doing this part on a separate Thread class thread (BackgroundWorker won't work since i need an STA thread). Everything is OK upto this point. But after displaying the print preview now i need to print, and clicking Print icon on the generated preview throws the infamous "The calling thread cannot access this object

How to access separate thread generated WPF UI elements from the Dispatcher thread?

亡梦爱人 提交于 2019-11-30 15:09:58
I need to generate a print preview (a long one) using wpf UI elements like FixedDocument, FlowDocument, PageContent, BlockUIContainer and all those. To keep my UI responsive i'm doing this part on a separate Thread class thread (BackgroundWorker won't work since i need an STA thread). Everything is OK upto this point. But after displaying the print preview now i need to print, and clicking Print icon on the generated preview throws the infamous "The calling thread cannot access this object because a different thread owns it." exception. So, is there any way around? EDIT (CODE): Dispatcher

Application.Current.Shutdown() vs. Application.Current.Dispatcher.BeginInvokeShutdown()

纵饮孤独 提交于 2019-11-30 13:22:37
问题 First a bit of background: I have a WPF application, which is a GUI-front-end to a legacy Win32-application. The legacy app runs as DLL in a separate thread. The commands the user chooses in the UI are invoked on that "legacy thread". If the "legacy thread" finishes, the GUI-front-end cannot do anything useful anymore, so I need to shutdown the WPF-application. Therefore, at the end of the thread's method, I call Application.Current.Shutdown() . Since I am not on the main thread, I need to

Springboot 的 @ComponentScan

纵饮孤独 提交于 2019-11-30 11:09:04
spring就是一个依赖注入框架,所有的内容都是关于bean的定义及其依赖关系 定义Spring Beans的第一步是使用正确的注解@Component或@Service或 @Repository 但是,Spring不知道你定义了某个bean除非它知道从哪里可以找到这个bean ComponentScan做的事情就是告诉Spring从哪里找到bean 由你来定义哪些包需要被扫描。一旦你指定了,Spring将会将在被指定的包及其下级包(sub packages)中寻找bean -- 扫描一个包 定义@CoponentScan(“com.demo”) 这么做扫描的范围扩大到整个父包com.demo -- 扫描两个包 定义分别扫描两个包 @ComponentScan({“com.demo.springboot”,”com.demo.somethingelse”}) 有的时候你回遇到这样的错误 WARNING: No mapping found for HTTP request with URI [/spring-mvc/login] in DispatcherServlet with name ‘dispatcher’ WARNING: No mapping found for HTTP request with URI [/list-todos] in

Is there any way to use Dispatcher on a non WPF thread ; new to multi threading

穿精又带淫゛_ 提交于 2019-11-30 07:58:37
Why does this not work? What I am trying to do: I need a way to run specific methods in a specific thread that lives on till the end of the program. My other possible options: As I understand a possible way to do it would be to implement a queue. Into which I could push in methods I want to be run in the specific thread. In the specific thread, I would be spinning and sleeping / monitor.pulse to see if there are delegates waiting to be run in the queue. My objective: Is to avoid all the hardwork to create the delegate queue, maintain lock etc. It appears that a ready made solution exists in

Application.Current.Shutdown() vs. Application.Current.Dispatcher.BeginInvokeShutdown()

为君一笑 提交于 2019-11-30 07:19:20
First a bit of background: I have a WPF application, which is a GUI-front-end to a legacy Win32-application. The legacy app runs as DLL in a separate thread. The commands the user chooses in the UI are invoked on that "legacy thread". If the "legacy thread" finishes, the GUI-front-end cannot do anything useful anymore, so I need to shutdown the WPF-application. Therefore, at the end of the thread's method, I call Application.Current.Shutdown() . Since I am not on the main thread, I need to invoke this command. However, then I noticed that the Dispatcher also has BeginInvokeShutdown() to

Error in C#: “An object reference is required for the non-static field, method, or property”

白昼怎懂夜的黑 提交于 2019-11-30 06:29:37
I wrote code in WPF. Firstly, I wrote a separate project to test work with a COM port device, and it worked well. Next I decided to integrate it in another project, but I get an error. I didn't change the code; I am just copied it into a new code file. This code works well: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation;