我正在撰写归结为文档编辑器的内容.当应用程序关闭时,我需要提示用户保存更改.这很容易.我的问题是什么时候不提示用户,而只是丢弃未保存的数据并关闭.
在FormClosing事件中,CloseReason枚举包括:
我认为WindowsShutDown和TaskManagerClosing不应该导致"保存更改?" 提示出现,以防止应用程序挂起该提示显示.
这是标准做法,还是我应该在这里做些什么呢?
为清楚起见,这是代码:
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
if (!(e.CloseReason == CloseReason.WindowsShutDown || e.CloseReason == CloseReason.TaskManagerClosing)
&& this.ChangesPending())
{
switch (MessageBox.Show(this, "Save changes?", "Save Changes", MessageBoxButtons.YesNoCancel))
{
case DialogResult.Yes:
this.Save();
break;
case DialogResult.No:
// Do nothing
break;
case DialogResult.Cancel:
e.Cancel = true;
break;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我不确定哪种方法是正确的,现在我只是exit(0)
在用户点击退出按钮时调用.
所以我让我的prism/mvvm/mef程序运行良好,用户在应用程序中输入数据,然后关闭应用程序(或关闭计算机).
如何通知程序关闭/计算机关闭的View(模型),以便它可以保存用户数据,也可以询问是否应保存这些数据?
关闭程序关闭的数据肯定是要避免的,并且在用户的每个按键上保存内容是没有意义的.
有没有办法在实际关闭之前获得JVM关闭或System.exit调用的通知?我想要这个,所以我的应用程序将能够彻底退出.我意识到这样的事情不太可能存在,但是,也许有这样的事情?
我目前有一个在 Windows 下运行的基于控制台的 python 程序。该程序将大部分数据保存在内存中,并定期将数据保存到磁盘,或者当用户通过键盘中断 ( Ctrl+ C) 事件关闭应用程序时。
我遇到的问题是,当用户点击控制台窗口右上角的“X”按钮时,会话关闭并且内存中的数据丢失。我正在寻找的是一个事件/信号或钩子,以便我可以在关闭之前清理内存。
我希望在没有任何外部库的情况下做到这一点,但如果这是不可能的,我仍然想知道如何做到这一点。
我正在检查Windows身份验证用户是否是我的wpf应用程序的有效用户.
如果没有,我需要关闭应用程序; 但即使在执行Application.Current.Shutdown(-1)之后,应用程序也会继续执行.
以下链接说我需要删除我的StartUpURI; 但我的app.xaml中没有这个标签.- > 从App.xaml.cs关闭WPF应用程序
编辑: - 我在APP.XAML.CS - >中有这个代码
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
this.exceptionPolicy = ConfigurationManager.AppSettings.Get("ExceptionPolicy");
this.displayErrorDetails = true;
this.container = new UnityContainer();
// Register services and types in Unity
RegisterServices();
// Check user
if (!IsValidUser())
{
//Application.Current.Shutdown();
App.Current.Shutdown();
}
}
Run Code Online (Sandbox Code Playgroud) 我希望在应用程序关闭后保存一些整数并在应用程序打开后恢复它们,最简单的方法是什么?
我正在使用 ThreadPoolTaskExecutor 编写 Spring Boot 应用程序。这是我的应用程序类:
import info.gandraweb.apns.service.MessageService;
import info.gandraweb.apns.settings.AppSettings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
@SpringBootApplication
@EnableScheduling
@EnableAutoConfiguration
@EnableAsync
public class Application implements AsyncConfigurer{
private static final Logger logger = LoggerFactory.getLogger(Application.class);
@Autowired
private AppSettings appSettings;
public static void main(String[] args) {
ApplicationContext applicationContext = SpringApplication.run(Application.class, args);
AppSettings appSettings = applicationContext.getBean(AppSettings.class);
logger.info(appSettings.toString());
test(applicationContext);
}
@Override
public Executor getAsyncExecutor() …
Run Code Online (Sandbox Code Playgroud) java executorservice application-shutdown threadpoolexecutor spring-boot
我正在编写一个小型控制台应用程序(将作为服务运行),它基本上在运行时启动 Java 应用程序,如果 Java 应用程序关闭则自行关闭,如果 Java 应用程序关闭则关闭 Java 应用程序。
我认为前两个工作正常,但我不知道如何检测 .NET 应用程序何时关闭,以便我可以在发生这种情况之前关闭 Java 应用程序。Google 搜索仅返回一堆有关检测 Windows 关闭的信息。
谁能告诉我如何处理该部分以及其余部分是否看起来不错?
namespace MinecraftDaemon
{
class Program
{
public static void LaunchMinecraft(String file, String memoryValue)
{
String memParams = "-Xmx" + memoryValue + "M" + " -Xms" + memoryValue + "M ";
String args = memParams + "-jar " + file + " nogui";
ProcessStartInfo processInfo = new ProcessStartInfo("java.exe", args);
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
try
{
using (Process minecraftProcess = Process.Start(processInfo))
{ …
Run Code Online (Sandbox Code Playgroud) 我使用它来构建它mvn clean package
并获取一个xxx.jar文件.跑$java -jar xxx.jar >> output.log &
开始吧,效果很好.
但大约两个小时后,它关机,为什么?这是一个答案,但不适合我>> /sf/answers/1568675881/
这是我的output.log:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.1.9.RELEASE) …
Run Code Online (Sandbox Code Playgroud)