如果您对如何重新启动C#WinForm应用程序?感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于如何重新启动C#WinForm应用程序?的详细内容,我们还将为您解答c#重启软
如果您对如何重新启动C#WinForm应用程序?感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于如何重新启动C#WinForm应用程序?的详细内容,我们还将为您解答c# 重启软件的相关问题,并且为您提供关于c# winform应用程序如何点击webview2下一个按钮?、c# – Winform应用程序,窗口最小化强制垃圾收集?、c# – Winform应用程序的Sharp架构?、c# – 关闭WinForm应用程序时的一次性对象生命周期的有价值信息。
本文目录一览:- 如何重新启动C#WinForm应用程序?(c# 重启软件)
- c# winform应用程序如何点击webview2下一个按钮?
- c# – Winform应用程序,窗口最小化强制垃圾收集?
- c# – Winform应用程序的Sharp架构?
- c# – 关闭WinForm应用程序时的一次性对象生命周期
如何重新启动C#WinForm应用程序?(c# 重启软件)
开发C#.NET 2.0 WinForm应用程序。需要应用程序关闭并自行重启。
Application.Restart();
上述方法已被证明是不可靠的。
什么是重启应用程序的更好方法?
答案1
小编典典不幸的是,您不能使用Process.Start()启动当前正在运行的进程的实例。根据Process.Start()文档:“如果该进程已经在运行,则不会启动其他进程资源…”
这项技术在VS调试器下可以很好地工作(因为VS做了某种魔术,导致Process.Start认为进程尚未运行),但是当不在调试器下运行时将失败。(请注意,这可能是特定于操作系统的-
我似乎记得在某些测试中,它可以在XP或Vista上运行,但我可能只是想起了在调试器下运行它。)
这项技术正是我目前正在研究的项目中的最后一个程序员所使用的技术,并且我已经尝试了很长时间了。到目前为止,我只找到一个解决方案,对我来说这感觉很肮脏又笨拙:启动第二个应用程序,该应用程序在后台等待第一个应用程序终止,然后重新启动第一个应用程序。我敢肯定它会起作用,但是,。
编辑:使用第二个应用程序的作品。我在第二个应用程序中所做的就是:
static void RestartApp(int pid, string applicationName ) { // Wait for the process to terminate Process process = null; try { process = Process.GetProcessById(pid); process.WaitForExit(1000); } catch (ArgumentException ex) { // ArgumentException to indicate that the // process doesn''t exist? LAME!! } Process.Start(applicationName, ""); }
(这是一个非常简化的示例。实际代码具有很多健全性检查,错误处理等)
c# winform应用程序如何点击webview2下一个按钮?
如何解决c# winform应用程序如何点击webview2下一个按钮??
下面的代码没有可供点击的任何名称或 ID。在那里所有班级自动更改,因此不可能根据我的知识检测班级。
你能帮我点击下一步按钮吗?
请看下面的HTML代码。
<divjsname="DH6Rkf" jscontroller="QEg9te" jsaction="rcuQ6b:rcuQ6b;PIvFg:vjx2Ld(Njthtb),ChoyC(eBSUOb),VaKChb(gVmDzc),nCZam(W3Rzrc),Tzaumc(uRHG6),JGhSzd;dcnbp:dE26Sc(lqvTlf);FzgWvd:JGhSzd;"
data-is-consent="false" data-is-primary-action-disabled="false" data-is-secondary-action-disabled="false" data-primary-action-label="Next"
data-secondary-action-label="" jsshadow="">
<divjsname="DhK0U">
<divjsname="k77Iif">
<div jscontroller="Xq93uf" jsaction="click:cOuCgd;jibuQc:jibuQc;" jsname="Njthtb">
<divdata-is-touch-wrapper="true">
<buttonjscontroller="soHxf" jsaction="click:cOuCgd; mousedown:UX7yZ; mouseup:lbsD7e; mouseenter:tfO1Yc; mouseleave:JywGue; touchstart:p6p2H; touchmove:FwuNnf; touchend:yfqBxc; touchcancel:JMtRjd; focus:AHmuwe; blur:O22p3e; contextmenu:mg9Pef;"
data-idom-jsname="LgbsSe" type="button">
<div></div>
<div></div>
<span jsname="V67aGc">Next</span>
</button>
</div>
</div>
</div>
<divjsname="QkNstf">
<div jscontroller="Xq93uf" jsaction="click:cOuCgd;jibuQc:jibuQc;" jsname="gVmDzc">
<divdata-is-touch-wrapper="true">
<buttonjscontroller="soHxf" jsaction="click:cOuCgd; mousedown:UX7yZ; mouseup:lbsD7e; mouseenter:tfO1Yc; mouseleave:JywGue; touchstart:p6p2H; touchmove:FwuNnf; touchend:yfqBxc; touchcancel:JMtRjd; focus:AHmuwe; blur:O22p3e; contextmenu:mg9Pef;"
data-idom-jsname="LgbsSe" type="button">
<div></div>
<div></div>
<span jsname="V67aGc">Back</span>
</button>
</div>
</div>
</div>
</div>
</div>
请参阅下文以了解我需要什么,但它不起作用。
webView21.ExecuteScriptAsync("document.getElementById(''next'').click();");
如果您是专家,请帮助我。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
c# – Winform应用程序,窗口最小化强制垃圾收集?
在初始启动时旋转高达~61,000K(初始数据网格和数据加载)
如果我最小化应用程序,不接触或做任何事情,内存使用量下降到1,380K.
当我恢复应用程序时,旋转回到只有5.8K
所以我的问题是,最小化是否会发送一些内部消息来清理资源,因为有问题的应用程序不是焦点?
我注意到的第一个应用程序恰好是VB.NET,但我在主要的C#winform应用程序中观察到了相同的行为.
解决方法
垃圾收集是一种虚拟内存操作.
c# – Winform应用程序的Sharp架构?
有没有人使用Sharp架构进行非Web项目?
经历如何?
这是否意味着当使用Sharp架构进行非Web用途时,有人将城堡作为IoC容器锁定?
如果不是Sharp Architecture,那么非web世界的一些受欢迎的应用程序框架是什么[spring.NET?]?
如果要开始一个绿色领域Winforms应用程序,什么应用程序框架将是可取的?
解决方法
c# – 关闭WinForm应用程序时的一次性对象生命周期
using (conn = OpenConnection()) { using (tran = conn.BeginTransaction()) { // Do stuff } }
现在,一些用户是住院病人,他们只是在应用程序在后台线程中有活动事务时关闭应用程序.我们的数据库管理员发现这些事务在数据库上仍然活动了几分钟甚至更长时间,这是一个问题,因为打开事务会锁定数据.
那么,当用户决定关闭应用程序时,这些线程中的线程和一次性对象会发生什么?线程是使用Task.StartNew()方法创建的.
解决方法
Foreground and Background Threads:
a background thread does not keep the managed execution environment running. Once all foreground threads have been stopped in a managed process (where the .exe file is a managed assembly),the system stops all background threads and shuts down.
这也适用于线程池中的线程,这些线程在启动新任务时默认使用,而不指定其他选项:
Task Schedulers
The default task scheduler is based on the .NET Framework 4 ThreadPool
Foreground and Background Threads:
Threads that belong to the managed thread pool (that is,threads whose IsThreadPoolThread property is true) are background threads.
关于申请终止的事实
在那之后,我还没有找到任何进一步的信息,在线程终止后发生了什么.我所做的,是简单的测试:
static void Main(string[] args) { Task.Factory.StartNew(Method); Task.Delay(1000); } static void Method() { try { while (true) { } } finally { File.WriteallText(@"C:\polygon\Test.txt","test"); } }
答案是,最终块没有被执行.
解决方案
ThreadAbortException – 不在这里
像ThreadAbortException这样的.NET中有一些功能称为线程终止的答案,但是:
When the common language runtime (CLR) stops background threads after all foreground threads in a managed executable have ended,it does not use Thread.Abort.
Process.Exited事件 – 不在这里
如果您运行其他进程,可以使用以下代码:
var myProcess = new Process(); myProcess.EnableRaisingEvents = true; myProcess.Exited += new EventHandler(CleanUp);
但是,对于当前流程,这也不起作用.
AppDomain.CurrentDomain.ProcessExit – 有效
但是,Avneesh建议的解决方案适用于当前流程:
static void Main(string[] args) { AppDomain.CurrentDomain.ProcessExit += CleanUp; Task.Factory.StartNew(Method); Task.Delay(1000); } static void Method() { try { while (true) { } } finally { CleanUp(null,EventArgs.Empty); } } static void CleanUp(object sender,EventArgs args) { File.WriteallText(@"C:\polygon\Test.txt","test"); }
流程终止
有关rosources的问题的答案可以在Terminating a Process文章中找到:
- Any remaining threads in the process are marked for termination.
- Any resources allocated by the process are freed.
- All kernel objects are closed.
- The process code is removed from memory.
- The process exit code is set.
- The process object is signaled.
以及如何终止进程:
- Any thread of the process calls the ExitProcess function. Note that some implementation of the C run-time library (CRT) call ExitProcess if the primary thread of the process returns.
- The last thread of the process terminates.
- Any thread calls the TerminateProcess function with a handle to the process.
- For console processes,the default console control handler calls ExitProcess when the console receives a CTRL+C or CTRL+BREAK signal.
- The user shuts down the system or logs off.
数据库连接
连接是一种资源,因此如果处理终止,则释放其所有资源.我检查了它在实践中的样子.
C#代码:
sqlConnection connection = new sqlConnection("Data Source=.;Initial Catalog=[database_name];Integrated Security=True"); connection.open(); Debugger.Launch(); connection.Close(); connection.dispose();
会话查找的T-SQL查询:
SELECT COUNT(*) FROM sys.dm_exec_sessions WHERE nt_user_name = '[user_name]' AND program_name = '.Net sqlClient Data Provider'
我注意到,对于每个新连接,都创建了新会话.最有趣的是,在明确关闭或处理连接后,该会话未被释放.但是 – 目前我们感兴趣的领域 – 会话在申请流程终止时被释放.
今天关于如何重新启动C#WinForm应用程序?和c# 重启软件的分享就到这里,希望大家有所收获,若想了解更多关于c# winform应用程序如何点击webview2下一个按钮?、c# – Winform应用程序,窗口最小化强制垃圾收集?、c# – Winform应用程序的Sharp架构?、c# – 关闭WinForm应用程序时的一次性对象生命周期等相关知识,可以在本站进行查询。
本文标签: