fsi event loop
来源:互联网 发布:c语言二维数组例子 编辑:程序博客网 时间:2024/06/06 01:57
在默认情况下fsi 中的Event loop是绑定到winform中的,如果我们在fsi中测试WPF的控件时,加载自定义的WPF控件,有些消息就无法正常响应。比如按键消息就无法正常响应。这时需要重定义fsi的Event loop。好在有现成的示例。
module WPFEventLoop =
open System
open System.Windows
open System.Windows.Threading
open Microsoft.FSharp.Compiler.Interactive
open Microsoft.FSharp.Compiler.Interactive.Settings
type RunDelegate<'b> = delegate of unit -> 'b
let Create() =
let app =
try
// Ensure the current application exists. This may fail, if it already does.
let app = new Application() in
// Create a dummy window to act as the main window for the application.
// Because we're in FSI we never want to clean this up.
new Window() |> ignore;
app
with :? InvalidOperationException -> Application.Current
let disp = app.Dispatcher
let restart = ref false
{ new IEventLoop with
member x.Run() =
app.Run() |> ignore
!restart
member x.Invoke(f) =
try
disp.Invoke(DispatcherPriority.Send,new RunDelegate<_>(fun () -> box(f ()))) |> unbox
with e -> eprintf "\n\n ERROR: %O\n" e; reraise()
member x.ScheduleRestart() = ()
//restart := true;
//app.Shutdown()
}
let Install() = fsi.EventLoop <- Create()
WPFEventLoop.Install()
运行之后按键消息就可以正常响应了。
module WPFEventLoop =
open System
open System.Windows
open System.Windows.Threading
open Microsoft.FSharp.Compiler.Interactive
open Microsoft.FSharp.Compiler.Interactive.Settings
type RunDelegate<'b> = delegate of unit -> 'b
let Create() =
let app =
try
// Ensure the current application exists. This may fail, if it already does.
let app = new Application() in
// Create a dummy window to act as the main window for the application.
// Because we're in FSI we never want to clean this up.
new Window() |> ignore;
app
with :? InvalidOperationException -> Application.Current
let disp = app.Dispatcher
let restart = ref false
{ new IEventLoop with
member x.Run() =
app.Run() |> ignore
!restart
member x.Invoke(f) =
try
disp.Invoke(DispatcherPriority.Send,new RunDelegate<_>(fun () -> box(f ()))) |> unbox
with e -> eprintf "\n\n ERROR: %O\n" e; reraise()
member x.ScheduleRestart() = ()
//restart := true;
//app.Shutdown()
}
let Install() = fsi.EventLoop <- Create()
WPFEventLoop.Install()
运行之后按键消息就可以正常响应了。
0 0
- fsi event loop
- Event Loop
- Event Loop
- Event Loop
- Event Loop
- Event loop
- Event Loop
- event loop
- glib main event loop
- Main event loop
- javascript Event Loop 小结
- 什么是 Event Loop?
- 什么是 Event Loop?
- event loop不是epoll
- 什么是 Event Loop?
- JavaScript Event Loop 浅析
- Libevent:4event loop
- GLIB main event loop
- Linux安装VMWare虚拟机(Kali)
- PCA的数学原理Matlab演示
- virtual override new之派生
- HDU - 2227 Find the nondecreasing subsequences (树状数组 + 子序列 + 离散化)
- Java多线程系列--“JUC锁”04之 公平锁(二)
- fsi event loop
- 好的开始
- 基于Zxing的二维码、条形码的扫描以及二维码的生成(简洁高效)
- 如何取得系统时间
- 我的高效编程的秘诀--开发环境的重要性(IOS)
- H264语法分析之-slice
- NoSQL架构实践(二)——以NoSQL为主
- jquery库与prototype库冲突的解决方法
- hunnu OJ 11564 Easy Delete(二维坐标的离散化处理+最大匹配)