登录
注册
开源
企业版
高校版
搜索
帮助中心
使用条款
关于我们
开源
企业版
高校版
私有云
模力方舟
AI 队友
登录
注册
轻量养虾,开箱即用!低 Token + 稳定算力,Gitee & 模力方舟联合出品的 PocketClaw 正式开售!点击了解详情
代码拉取完成,页面将自动刷新
开源项目
>
程序开发
>
图形UI组件/框架
&&
捐赠
捐赠前请先登录
取消
前往登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
Watch
不关注
关注所有动态
仅关注版本发行动态
关注但不提醒动态
245
Star
2.1K
Fork
489
GVP
dotNET China
/
NanUI
代码
Issues
0
Pull Requests
0
统计
流水线
服务
质量分析
Jenkins for Gitee
腾讯云托管
腾讯云 Serverless
悬镜安全
阿里云 SAE
Codeblitz
SBOM
开发画像分析
我知道了,不再自动展开
更新失败,请稍后重试!
移除标识
内容风险标识
本任务被
标识为内容中包含有代码安全 Bug 、隐私泄露等敏感信息,仓库外成员不可访问
程序运行大概2或3天后白屏,像是浏览器进程崩溃
已完成
#IANK79
LUBG
创建于
2024-08-30 10:41
程序运行大概2或3天后白屏,像是浏览器进程崩溃; ``` internal class MyApp : WinFormiumStartup { protected override MainWindowCreationAction? UseMainWindow(MainWindowOptions opts) { return opts.UseMainFormium<MyWindow>(); // 可以指定 Formium 为主窗体,也可以使用原生的 WinForm 窗体。 // You can specify Formium as the main form, or you can use the native WinForm form. //return opts.UseMainForm<Form1>(); } protected override void WinFormiumMain(string[] args) { // 现在把 Main 函数搬到这里来。避免用户搞不清主进程和渲染进程的区别,在 Program.cs 里面写太多代码导致子进程内部出现问题。 // Now move the Main function here. To avoid users not knowing the difference between the main process and the rendering process, write too much code in Program.cs, which causes problems in the sub-process. #if NETCOREAPP3_1_OR_GREATER // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); #else Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); #endif } // CEF 的配置可以在Program.cs里面写,也可以在这里写,在这里写更集中,更简洁。 // CEF configuration can be written in Program.cs or here, which is more centralized and concise here. protected override void ConfigurationChromiumEmbedded(ChromiumEnvironmentBuiler cef) { cef.DisableHiDpiSupport(); cef.ConfigureCommandLineArguments(cmdLine => { cmdLine.AppendArgument("disable-web-security"); cmdLine.AppendSwitch("no-proxy-server"); cmdLine.AppendSwitch("disable-gpu"); cmdLine.AppendSwitch("--js-flags", $"--max_old_space_size=2048"); }); cef.ConfigureDefaultSettings(settings => { settings.WindowlessRenderingEnabled = true; settings.MultiThreadedMessageLoop = true; settings.LogSeverity = CefLogSeverity.Error; settings.RootCachePath = Environment.CurrentDirectory; settings.CachePath = Path.Combine(Environment.CurrentDirectory, "logs\\CefCache"); if (!Directory.Exists(settings.CachePath)) { Directory.CreateDirectory(settings.CachePath); } settings.Locale = "zh-CN"; settings.LogFile = "logs\\CefCache\\CefGlue.log"; settings.MultiThreadedMessageLoop = true; }); //cef.ConfigureSubprocess(sub => //{ // // 指定 Subprocess 的文件路径 // sub.SubprocessFilePath = "WinFormiumSubProcess.exe"; //}); cef.ConfigureDefaultBrowserSettings(settings => { settings.DefaultEncoding = "utf-8"; }); } protected override void ConfigureServices(IServiceCollection services) { // 注册嵌入资源 // Register embedded resources to specific domain. services.AddEmbeddedFileResource(new EmbeddedFileResourceOptions { Scheme = "http", DomainName = "embeddefile.app.local", ResourceAssembly = typeof(Program).Assembly, EmbeddedResourceDirectoryName = @"EmbeddedFiles\client-ui", }); // 注册本地资源 // Register local resources to specific domain. services.AddLocalFileResource(new LocalFileResourceOptions { Scheme = "http", DomainName = "res.app.local", PhysicalFilePath = Path.Combine(AppContext.BaseDirectory, @"EmbeddedFiles\client-ui"), }); services.AddDataResource("http", "api.app.local", provider => { provider.ImportFromCurrentAssembly(); // 从当前程序集导入数据服务 }); // 注册 JavaScript Window Binding Object // Register JavaScript Window Binding Object //services.AddWindowBindingObject<TestWindowBindingObject>(); } ``` ``` internal class MyWindow : Formium { ChromiumEnvironment chromenv; public MyWindow() { Loaded += MyWindow_Loaded; PageLoadEnd += MyWindow_PageLoadEnd; Resize += MyWindow_Resize; Closed += MyWindow_Closed; } protected override FormStyle ConfigureWindowStyle(WindowStyleBuilder builder) { // 此处配置窗口的样式和属性,或留空以使用默认样式 var style = builder.UseSystemForm(); style.TitleBar = true; //style.DefaultAppTitle = "My first WinFomrim app"; return style; } private void MyWindow_Resize(object? sender, EventArgs e) { if (sender is Formium f) { //f.GetHostWindow().Invalidate(); foreach (Control item in f.GetHostWindow().Controls) { item.Invalidate(); } } } public MyWindow(ChromiumEnvironment env) // 依赖注入测试; Dependency Injection Testing; { chromenv = env; //默认测试,加载普通网页 //Default test, load web page //Url = "https://www.bing.com"; //测试加载本地资源 //Test loading local resources //Url = "http://static.app.local/"; //测试嵌入资源 //Test loading embedded resources //Url = "http://embedded.app.local/"; //错误地址测试,指定了错误页面的地址,如果页面加载失败,将会自动显示WinFormium内置的错误页面。 //Error address test specifies the address of the error page. If the page fails to load, WinFormium's built-in error page will be automatically displayed. //Url = "http://static1.app.local/"; //注意,默认没有指定任何Url,新版WinFormium将会自动加载一个欢迎页面。 //If no URL is specified, WinFormium will automatically load a welcome page. Url = "http://res.app.local/"; //这个事件对应WinForm的Load事件,对应NanUI的OnReady抽象方法 //OnReady of old version NanUI Loaded += MyWindow_Loaded; this.EnableSplashScreen = true; this.AppTitle = "机柜客户端"; PageLoadEnd += MyWindow_PageLoadEnd; Closed += MyWindow_Closed; //启动后台数据服务进程 MainDoWork(); } protected override void PaintSplashScreen(PaintEventArgs e) { //e.Graphics.Clear(Color.Yellow); //e.Graphics.DrawString("Loading...", SystemFonts.DefaultFont, Brushes.Black, 10, 10); // 读取图片 using (Image image = Image.FromFile(Environment.CurrentDirectory+"/splash.png")) { Graphics g = e.Graphics; Rectangle ClientRectangle = e.ClipRectangle; // 计算缩放比例以填充整个窗口 float widthRatio = (float)ClientRectangle.Width / image.Width; float heightRatio = (float)ClientRectangle.Height / image.Height; float ratio = Math.Max(widthRatio, heightRatio); // 如果需要,对图像进行缩放 if (ratio > 1) { SizeF newSize = new SizeF(image.Width * ratio, image.Height * ratio); g.DrawImage(image, new RectangleF(new PointF((ClientRectangle.Width - newSize.Width) / 2, (ClientRectangle.Height - newSize.Height) / 2), newSize)); } else { // 图像已经足够大,不需要缩放 g.DrawImage(image, new Rectangle(0, 0, ClientRectangle.Width, ClientRectangle.Height)); } // 在窗体上绘制图片 //e.Graphics.DrawImage(image, 0, 0, image.Width, image.Height); } } private void MyWindow_Loaded(object? sender, BrowserEventArgs e) { this.WindowState = FormiumWindowState.Maximized; this.Closing += MyWindow_Closed; var frame = e.Browser.GetMainFrame(); if (File.Exists(System.AppDomain.CurrentDomain.BaseDirectory + "./fullscreen.txt")) { this.WindowState |= FormiumWindowState.FullScreen; } // 测试JS对象映射 // Test JS object mapping TestJSObjectMapping(frame); // 注册前端消息处理器,比如这里注册bbb,那么在前端调用 formium.postMessage("bbb", "[任意数据类型/字符/数字/数组/对象]")来向这个处理器发送消息。 // Register front-end message handler. For example, by registering “bbb” here, you can send messages to this handler from the front-end using the formium.postMessage("bbb", "[any data type/string/number/array/object]") method. //RegisterJavaScriptMessagHandler("bbb", args => //{ // //}); // 注册前端请求处理器,请求处理和消息处理器的不同在于,消息处理器不需要返回结果,而请求处理器需要返回结果。 // Register front-end request handler. The difference between a request handler and a message handler is that a request handler needs to return a result. // 请求处理器提供了2中不同的接口返回数据,一种是同步接口,一种是异步接口。 // The request handler provides two different interfaces for returning data: synchronous and asynchronous. // 这是同步接口,前端使用 formium.sendHostWindowRequest("rrr", "[任意数据类型/字符/数字/数组/对象]") 来向这个处理器发送请求,这个请求会阻塞前端线程,直到这个处理器返回结果。 // This is the synchronous interface. The front-end can send a request to this handler using formium.sendHostWindowRequest("rrr", "[any data type/string/number/array/object]"), and this request will block the front-end thread until the handler returns a result. //RegisterJavaScriptRequestHandler("rrr", args => "OK sync"); // 这是异步接口,前端使用 formium.sendHostWindowRequestAsync("aaa", "[任意数据类型/字符/数字/数组/对象]") 来向这个处理器发送请求,这个请求不会阻塞前端线程,前端线程会继续执行,使用promise参数的resolve([data: any])或者reject([reason: string])方法来指定这个异步是否成功执行。 // This is the asynchronous interface. The front-end can send a request to this handler using formium.sendHostWindowRequestAsync("aaa", "[any data type/string/number/array/object]"), and this request will not block the front-end thread. The front-end thread will continue executing, and you can use the resolve([data: any]) or reject([reason: string]) methods of the promise parameter to specify whether this asynchronous operation is successfully executed. // 前端的formium.sendHostWindowRequestAsync()方法将返回一个可等待的promise对象,可以使用await关键字来等待这个promise对象的执行结果。当然,使用传统的then/catch方法也可以。 // The front-end's formium.sendHostWindowRequestAsync() method will return a awaitable promise object. You can use the await keyword to wait for the execution result of this promise object. Alternatively, you can also use the traditional then/catch methods. //RegisterJavaScriptRequestHandler("aaa", async (args, promise) => { // await Task.Delay(3000); // promise.Resolve("OK async"); //}); } private void MyWindow_Closed(object?sender,EventArgs e) { GlobaleLog.CommonFunc.printGlobalInfo(" 客户端关闭 > " ); Console.WriteLine("closeing......"); //Application.Exit(); Environment.Exit(0); } private void MyWindow_PageLoadEnd(object? sender, PageLoadEndEventArgs e) { /* //测试JS引擎 //Test JS engine TestJSEngine(); //测试从后端Post消息到前端,前端需要使用formium.addMessageDispatcher("test", msg=>{})方法来接收消息。 //Test post message from back-end to front-end, the front-end needs to use the formium.addMessageDispatcher("test", msg=>{}) method to receive the message. Task.Run(async () => { while (true) { await Task.Delay(5000); PostJavaScriptMessage("test", DateTime.Now); } }); */ } // 使用对象映射的方式来为WinFormium提供可前后端交互的JavaScript对象。 // Use object mapping to provide JavaScript objects that can interact with the front and back ends for WinFormium. private void TestJSObjectMapping(CefFrame frame) { var obj = new JavaScriptObject { }; obj.Add("exit", args => { WinFormiumApp.Shutdown(); return null; }); obj.Add("getData", async (args, promise) => { InvokeOnUIThread(() => { try { this.WindowState = FormiumWindowState.FullScreen; }catch (Exception ex) { Console.WriteLine(ex.Message); } }); }); //全屏方法 obj.Add("fullscreen", async (args, promise) => { InvokeOnUIThread(() => { this.WindowState = FormiumWindowState.FullScreen; }); }); //前端日志打开方法 obj.Add("openinfowin", (args, promise) => { InvokeOnUIThread(() => { Task.Run(() => { Shell.CreateConsole(); }); }); }); obj.Add("opensettingwin", (args, promise) => { InvokeOnUIThread(() => { Task.Run(() => { WinccClient.Utils.AppSettingUtil.OpenSettingForm(); }); }); }); //接收前端数据方法 obj.Add("recvUIDataEvent", (args, promise) => { try { recvUIDataEvent(args); } catch (Exception ex) { Console.WriteLine(ex.Message); } }); var hbrjso = BeginRegisterJavaScriptObject(frame); RegisterJavaScriptObject(hbrjso, "JsHelper", obj); EndRegisterJavaScriptObject(hbrjso); } /// <summary> /// 接收前台数据方法 /// </summary> /// <param name="data"></param> private void recvUIDataEvent(JavaScriptArray data) { Task.Run(() => { try { GlobaleLog.CommonFunc.printGlobalInfo(" 接收到前端设参 > "+data[0].GetString()); WinccClient.Utils.WebSocketUtil.GetInstance().doWriteWorkExecute_redirectEvery("setting", data[0].GetString()); } catch (Exception ex) { Console.WriteLine(ex); } }); } private static WinccClient.MainClass winccclientobj = WinccClient.MainClass.GetInstance(); private void MainDoWork() { Task.Run(() => { try { winccclientobj.doWork(); initPushTimer(); } catch (Exception ex) { Console.WriteLine(ex); } }); } internal static System.Timers.Timer PusDaataWaitTimer { get; } = new System.Timers.Timer { AutoReset = true, Interval = 1000, Enabled = false }; private void initPushTimer() { PusDaataWaitTimer.Elapsed += new System.Timers.ElapsedEventHandler(updagePagePhotoData); PusDaataWaitTimer.Enabled = true; } /// <summary> /// 向前台推送快照数据 /// 一定要异步,否则容易界面卡死 /// </summary> public void updagePagePhotoData(object sender, System.Timers.ElapsedEventArgs e) { PusDaataWaitTimer.Enabled = false; try { Dictionary<string, RcvDataModel> plcdata = WinccClient.Utils.PlcDataUtil.getplcCachesPhoto(); Task<JavaScriptResult> t = EvaluateJavaScriptAsync("updatepagedata(" + JObject.FromObject(plcdata).ToString() + ")"); t.Wait(); //Console.WriteLine(t.Result); Thread.Sleep(100); } catch (Exception ex) { CommonHelper.ShowInfo(ex); PusDaataWaitTimer.Enabled = true; } finally { PusDaataWaitTimer.Enabled = true; } } } ```
程序运行大概2或3天后白屏,像是浏览器进程崩溃; ``` internal class MyApp : WinFormiumStartup { protected override MainWindowCreationAction? UseMainWindow(MainWindowOptions opts) { return opts.UseMainFormium<MyWindow>(); // 可以指定 Formium 为主窗体,也可以使用原生的 WinForm 窗体。 // You can specify Formium as the main form, or you can use the native WinForm form. //return opts.UseMainForm<Form1>(); } protected override void WinFormiumMain(string[] args) { // 现在把 Main 函数搬到这里来。避免用户搞不清主进程和渲染进程的区别,在 Program.cs 里面写太多代码导致子进程内部出现问题。 // Now move the Main function here. To avoid users not knowing the difference between the main process and the rendering process, write too much code in Program.cs, which causes problems in the sub-process. #if NETCOREAPP3_1_OR_GREATER // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); #else Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); #endif } // CEF 的配置可以在Program.cs里面写,也可以在这里写,在这里写更集中,更简洁。 // CEF configuration can be written in Program.cs or here, which is more centralized and concise here. protected override void ConfigurationChromiumEmbedded(ChromiumEnvironmentBuiler cef) { cef.DisableHiDpiSupport(); cef.ConfigureCommandLineArguments(cmdLine => { cmdLine.AppendArgument("disable-web-security"); cmdLine.AppendSwitch("no-proxy-server"); cmdLine.AppendSwitch("disable-gpu"); cmdLine.AppendSwitch("--js-flags", $"--max_old_space_size=2048"); }); cef.ConfigureDefaultSettings(settings => { settings.WindowlessRenderingEnabled = true; settings.MultiThreadedMessageLoop = true; settings.LogSeverity = CefLogSeverity.Error; settings.RootCachePath = Environment.CurrentDirectory; settings.CachePath = Path.Combine(Environment.CurrentDirectory, "logs\\CefCache"); if (!Directory.Exists(settings.CachePath)) { Directory.CreateDirectory(settings.CachePath); } settings.Locale = "zh-CN"; settings.LogFile = "logs\\CefCache\\CefGlue.log"; settings.MultiThreadedMessageLoop = true; }); //cef.ConfigureSubprocess(sub => //{ // // 指定 Subprocess 的文件路径 // sub.SubprocessFilePath = "WinFormiumSubProcess.exe"; //}); cef.ConfigureDefaultBrowserSettings(settings => { settings.DefaultEncoding = "utf-8"; }); } protected override void ConfigureServices(IServiceCollection services) { // 注册嵌入资源 // Register embedded resources to specific domain. services.AddEmbeddedFileResource(new EmbeddedFileResourceOptions { Scheme = "http", DomainName = "embeddefile.app.local", ResourceAssembly = typeof(Program).Assembly, EmbeddedResourceDirectoryName = @"EmbeddedFiles\client-ui", }); // 注册本地资源 // Register local resources to specific domain. services.AddLocalFileResource(new LocalFileResourceOptions { Scheme = "http", DomainName = "res.app.local", PhysicalFilePath = Path.Combine(AppContext.BaseDirectory, @"EmbeddedFiles\client-ui"), }); services.AddDataResource("http", "api.app.local", provider => { provider.ImportFromCurrentAssembly(); // 从当前程序集导入数据服务 }); // 注册 JavaScript Window Binding Object // Register JavaScript Window Binding Object //services.AddWindowBindingObject<TestWindowBindingObject>(); } ``` ``` internal class MyWindow : Formium { ChromiumEnvironment chromenv; public MyWindow() { Loaded += MyWindow_Loaded; PageLoadEnd += MyWindow_PageLoadEnd; Resize += MyWindow_Resize; Closed += MyWindow_Closed; } protected override FormStyle ConfigureWindowStyle(WindowStyleBuilder builder) { // 此处配置窗口的样式和属性,或留空以使用默认样式 var style = builder.UseSystemForm(); style.TitleBar = true; //style.DefaultAppTitle = "My first WinFomrim app"; return style; } private void MyWindow_Resize(object? sender, EventArgs e) { if (sender is Formium f) { //f.GetHostWindow().Invalidate(); foreach (Control item in f.GetHostWindow().Controls) { item.Invalidate(); } } } public MyWindow(ChromiumEnvironment env) // 依赖注入测试; Dependency Injection Testing; { chromenv = env; //默认测试,加载普通网页 //Default test, load web page //Url = "https://www.bing.com"; //测试加载本地资源 //Test loading local resources //Url = "http://static.app.local/"; //测试嵌入资源 //Test loading embedded resources //Url = "http://embedded.app.local/"; //错误地址测试,指定了错误页面的地址,如果页面加载失败,将会自动显示WinFormium内置的错误页面。 //Error address test specifies the address of the error page. If the page fails to load, WinFormium's built-in error page will be automatically displayed. //Url = "http://static1.app.local/"; //注意,默认没有指定任何Url,新版WinFormium将会自动加载一个欢迎页面。 //If no URL is specified, WinFormium will automatically load a welcome page. Url = "http://res.app.local/"; //这个事件对应WinForm的Load事件,对应NanUI的OnReady抽象方法 //OnReady of old version NanUI Loaded += MyWindow_Loaded; this.EnableSplashScreen = true; this.AppTitle = "机柜客户端"; PageLoadEnd += MyWindow_PageLoadEnd; Closed += MyWindow_Closed; //启动后台数据服务进程 MainDoWork(); } protected override void PaintSplashScreen(PaintEventArgs e) { //e.Graphics.Clear(Color.Yellow); //e.Graphics.DrawString("Loading...", SystemFonts.DefaultFont, Brushes.Black, 10, 10); // 读取图片 using (Image image = Image.FromFile(Environment.CurrentDirectory+"/splash.png")) { Graphics g = e.Graphics; Rectangle ClientRectangle = e.ClipRectangle; // 计算缩放比例以填充整个窗口 float widthRatio = (float)ClientRectangle.Width / image.Width; float heightRatio = (float)ClientRectangle.Height / image.Height; float ratio = Math.Max(widthRatio, heightRatio); // 如果需要,对图像进行缩放 if (ratio > 1) { SizeF newSize = new SizeF(image.Width * ratio, image.Height * ratio); g.DrawImage(image, new RectangleF(new PointF((ClientRectangle.Width - newSize.Width) / 2, (ClientRectangle.Height - newSize.Height) / 2), newSize)); } else { // 图像已经足够大,不需要缩放 g.DrawImage(image, new Rectangle(0, 0, ClientRectangle.Width, ClientRectangle.Height)); } // 在窗体上绘制图片 //e.Graphics.DrawImage(image, 0, 0, image.Width, image.Height); } } private void MyWindow_Loaded(object? sender, BrowserEventArgs e) { this.WindowState = FormiumWindowState.Maximized; this.Closing += MyWindow_Closed; var frame = e.Browser.GetMainFrame(); if (File.Exists(System.AppDomain.CurrentDomain.BaseDirectory + "./fullscreen.txt")) { this.WindowState |= FormiumWindowState.FullScreen; } // 测试JS对象映射 // Test JS object mapping TestJSObjectMapping(frame); // 注册前端消息处理器,比如这里注册bbb,那么在前端调用 formium.postMessage("bbb", "[任意数据类型/字符/数字/数组/对象]")来向这个处理器发送消息。 // Register front-end message handler. For example, by registering “bbb” here, you can send messages to this handler from the front-end using the formium.postMessage("bbb", "[any data type/string/number/array/object]") method. //RegisterJavaScriptMessagHandler("bbb", args => //{ // //}); // 注册前端请求处理器,请求处理和消息处理器的不同在于,消息处理器不需要返回结果,而请求处理器需要返回结果。 // Register front-end request handler. The difference between a request handler and a message handler is that a request handler needs to return a result. // 请求处理器提供了2中不同的接口返回数据,一种是同步接口,一种是异步接口。 // The request handler provides two different interfaces for returning data: synchronous and asynchronous. // 这是同步接口,前端使用 formium.sendHostWindowRequest("rrr", "[任意数据类型/字符/数字/数组/对象]") 来向这个处理器发送请求,这个请求会阻塞前端线程,直到这个处理器返回结果。 // This is the synchronous interface. The front-end can send a request to this handler using formium.sendHostWindowRequest("rrr", "[any data type/string/number/array/object]"), and this request will block the front-end thread until the handler returns a result. //RegisterJavaScriptRequestHandler("rrr", args => "OK sync"); // 这是异步接口,前端使用 formium.sendHostWindowRequestAsync("aaa", "[任意数据类型/字符/数字/数组/对象]") 来向这个处理器发送请求,这个请求不会阻塞前端线程,前端线程会继续执行,使用promise参数的resolve([data: any])或者reject([reason: string])方法来指定这个异步是否成功执行。 // This is the asynchronous interface. The front-end can send a request to this handler using formium.sendHostWindowRequestAsync("aaa", "[any data type/string/number/array/object]"), and this request will not block the front-end thread. The front-end thread will continue executing, and you can use the resolve([data: any]) or reject([reason: string]) methods of the promise parameter to specify whether this asynchronous operation is successfully executed. // 前端的formium.sendHostWindowRequestAsync()方法将返回一个可等待的promise对象,可以使用await关键字来等待这个promise对象的执行结果。当然,使用传统的then/catch方法也可以。 // The front-end's formium.sendHostWindowRequestAsync() method will return a awaitable promise object. You can use the await keyword to wait for the execution result of this promise object. Alternatively, you can also use the traditional then/catch methods. //RegisterJavaScriptRequestHandler("aaa", async (args, promise) => { // await Task.Delay(3000); // promise.Resolve("OK async"); //}); } private void MyWindow_Closed(object?sender,EventArgs e) { GlobaleLog.CommonFunc.printGlobalInfo(" 客户端关闭 > " ); Console.WriteLine("closeing......"); //Application.Exit(); Environment.Exit(0); } private void MyWindow_PageLoadEnd(object? sender, PageLoadEndEventArgs e) { /* //测试JS引擎 //Test JS engine TestJSEngine(); //测试从后端Post消息到前端,前端需要使用formium.addMessageDispatcher("test", msg=>{})方法来接收消息。 //Test post message from back-end to front-end, the front-end needs to use the formium.addMessageDispatcher("test", msg=>{}) method to receive the message. Task.Run(async () => { while (true) { await Task.Delay(5000); PostJavaScriptMessage("test", DateTime.Now); } }); */ } // 使用对象映射的方式来为WinFormium提供可前后端交互的JavaScript对象。 // Use object mapping to provide JavaScript objects that can interact with the front and back ends for WinFormium. private void TestJSObjectMapping(CefFrame frame) { var obj = new JavaScriptObject { }; obj.Add("exit", args => { WinFormiumApp.Shutdown(); return null; }); obj.Add("getData", async (args, promise) => { InvokeOnUIThread(() => { try { this.WindowState = FormiumWindowState.FullScreen; }catch (Exception ex) { Console.WriteLine(ex.Message); } }); }); //全屏方法 obj.Add("fullscreen", async (args, promise) => { InvokeOnUIThread(() => { this.WindowState = FormiumWindowState.FullScreen; }); }); //前端日志打开方法 obj.Add("openinfowin", (args, promise) => { InvokeOnUIThread(() => { Task.Run(() => { Shell.CreateConsole(); }); }); }); obj.Add("opensettingwin", (args, promise) => { InvokeOnUIThread(() => { Task.Run(() => { WinccClient.Utils.AppSettingUtil.OpenSettingForm(); }); }); }); //接收前端数据方法 obj.Add("recvUIDataEvent", (args, promise) => { try { recvUIDataEvent(args); } catch (Exception ex) { Console.WriteLine(ex.Message); } }); var hbrjso = BeginRegisterJavaScriptObject(frame); RegisterJavaScriptObject(hbrjso, "JsHelper", obj); EndRegisterJavaScriptObject(hbrjso); } /// <summary> /// 接收前台数据方法 /// </summary> /// <param name="data"></param> private void recvUIDataEvent(JavaScriptArray data) { Task.Run(() => { try { GlobaleLog.CommonFunc.printGlobalInfo(" 接收到前端设参 > "+data[0].GetString()); WinccClient.Utils.WebSocketUtil.GetInstance().doWriteWorkExecute_redirectEvery("setting", data[0].GetString()); } catch (Exception ex) { Console.WriteLine(ex); } }); } private static WinccClient.MainClass winccclientobj = WinccClient.MainClass.GetInstance(); private void MainDoWork() { Task.Run(() => { try { winccclientobj.doWork(); initPushTimer(); } catch (Exception ex) { Console.WriteLine(ex); } }); } internal static System.Timers.Timer PusDaataWaitTimer { get; } = new System.Timers.Timer { AutoReset = true, Interval = 1000, Enabled = false }; private void initPushTimer() { PusDaataWaitTimer.Elapsed += new System.Timers.ElapsedEventHandler(updagePagePhotoData); PusDaataWaitTimer.Enabled = true; } /// <summary> /// 向前台推送快照数据 /// 一定要异步,否则容易界面卡死 /// </summary> public void updagePagePhotoData(object sender, System.Timers.ElapsedEventArgs e) { PusDaataWaitTimer.Enabled = false; try { Dictionary<string, RcvDataModel> plcdata = WinccClient.Utils.PlcDataUtil.getplcCachesPhoto(); Task<JavaScriptResult> t = EvaluateJavaScriptAsync("updatepagedata(" + JObject.FromObject(plcdata).ToString() + ")"); t.Wait(); //Console.WriteLine(t.Result); Thread.Sleep(100); } catch (Exception ex) { CommonHelper.ShowInfo(ex); PusDaataWaitTimer.Enabled = true; } finally { PusDaataWaitTimer.Enabled = true; } } } ```
评论 (
2
)
登录
后才可以发表评论
状态
已完成
待办的
进行中
已完成
已关闭
负责人
未设置
标签
未设置
标签管理
里程碑
未关联里程碑
未关联里程碑
Pull Requests
未关联
未关联
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
未关联
分支 (
-
)
标签 (
-
)
开始日期   -   截止日期
-
置顶选项
不置顶
置顶等级:高
置顶等级:中
置顶等级:低
优先级
不指定
严重
主要
次要
不重要
参与者(2)
C#
1
https://gitee.com/dotnetchina/NanUI.git
git@gitee.com:dotnetchina/NanUI.git
dotnetchina
NanUI
NanUI
点此查找更多帮助
搜索帮助
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册