- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我制作了一个 Windows 应用程序,然后运行它。然后我从应用程序选项卡的任务管理器中关闭该应用程序,然后单击结束任务按钮。然后我的 .txt 日志已成功创建。然后他们是任务管理器中另一个名为 PROCESS TAB 的 TAB,但是当我结束该应用程序的进程时,我的日志文件没有创建。
这是我的代码。
public bool eventHandled;
private int elapsedTime;
public Form1()
{
elapsedTime = 0;
InitializeComponent();
//From here Log created when we click from application atb
this.Size = new System.Drawing.Size(300, 300);
this.Text = "Form1";
LogWrite("Application Start At :");
}
public static void LogWrite(string logMessage){
try {
string path = @"D:\oldCode\log.txt";
if (!File.Exists(path))
{
File.Create(path);
TextWriter tw = new StreamWriter(path);
tw.Close();
}
using (StreamWriter w = File.AppendText(path))
{
Log(logMessage, w);
}
}
catch (Exception ex)
{
}
}
//event handler for termination of a process
public static void Log(string logMessage, TextWriter txtWriter)
{
try
{
txtWriter.Write("\r\n"+logMessage);
txtWriter.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(),
DateTime.Now.ToLongDateString());
//txtWriter.WriteLine(" :");
//txtWriter.WriteLine(" :{0}", logMessage);
txtWriter.WriteLine("-------------------------------");
}
catch (Exception ex)
{
}
}
class MyApplicationContext : ApplicationContext {
private int formCount;
private Form1 form1;
private Rectangle form1Position;
////private FileStream userData;
private MyApplicationContext() {
formCount = 0;
// Handle the ApplicationExit event to know when the application is exiting.
Application.ApplicationExit += new EventHandler(this.OnApplicationExit);
// Create both application forms and handle the Closed event
// to know when both forms are closed.
form1 = new Form1();
form1.Closed += new EventHandler(OnFormClosed);
form1.Closing += new CancelEventHandler(OnFormClosing);
// form1.Closing += new CancelEventHandler(onprocesscloase);
formCount++;
// Get the form positions based upon the user specific data.
form1.Show();
// this is for PROCESS to kill it
Process myProcess = new Process();
myProcess.StartInfo.FileName = "";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.EnableRaisingEvents = true;
myProcess.Exited += new EventHandler(myProcesses_Exited);
}
//METHOD TO KILL PROCESS
private void myProcesses_Exited(object sender, EventArgs e)
{
//Process ps = (Process) sender;
//messageBox.Text = ps.ProcessName;
//messageBox.Text = " has exited";
// MessageBox.Show("Exited event caught");
LogWrite("Application Start At :");
// myProcess.CloseMainWindow();
}
private void OnApplicationExit(object sender, EventArgs e) {
// When the application is exiting, write the application data to the
// user file and close it.
}
private void OnFormClosing(object sender, CancelEventArgs e) {
// When a form is closing, remember the form position so it
// can be saved in the user data file.
if (sender is Form1)
form1Position = ((Form)sender).Bounds;
}
private void OnFormClosed(object sender, EventArgs e) {
// When a form is closed, decrement the count of open forms.
// When the count gets to 0, exit the app by calling
// ExitThread().
formCount--;
if (formCount == 0) {
LogWrite("Application End At :");
ExitThread();
}
}
[STAThread]
static void Main(string[] args) {
// Create the MyApplicationContext, that derives from ApplicationContext,
// that manages when the application should exit.
MyApplicationContext context = new MyApplicationContext();
// Run the application with the specific context. It will exit when
// all forms are closed.
Application.Run(context);
}
}
最佳答案
列夫是正确的。当您从“应用程序”选项卡中单击“结束任务”时,Windows 会向您的应用程序发送一条 WM_CLOSE 消息。这与单击红色 X 关闭按钮或在应用程序的主窗体上调用 Me.Close 相同。发生这种情况时,您的表单关闭事件将被触发,您的应用程序可以正常关闭。
当您单击“进程”选项卡中的“结束进程”按钮时,Windows 只会终止您的进程,并且不会触发任何事件。
您可以通过运行 Spy++ 并让它监视发送到您的应用程序的消息来验证这一点。当您从“进程”选项卡终止应用程序时,您不会看到任何消息发送到您的应用程序。
就像您可以通过单击“开始”>“关机”来关闭 Windows,Windows 将正常关闭,或者您只需从墙上拔下插头,计算机就会立即关闭。
如果应用程序从“进程”选项卡终止,您将无能为力。
关于c# - 当我们从任务管理器中的进程选项卡关闭应用程序时如何获取登录.txt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22035866/
在 Android 的 API > 19 中是否有任何方法可以获取可移动 SD 卡的路径? 与外部 SD 卡一样,我们有 Environment.getExternalStorageDirectory
一些 Android 设备有 microSD(或其他存储卡)插槽,通常安装为 /storage/sdcard1 据我所知,自 Android 4.4 起 Google 限制了对此内存的访问,并在 An
我使用 Java Card 2.1.2 SDK 和 GPShell 作为与设备通信的方式在 Java Card 上构建一个项目。我从 GpShell 测试了 helloworld 示例,并成功发送了
我开发了一个应用程序,它有一个来电接收器,它适用于所有手机。一位用户有一部双 SIM 卡安卓手机。该应用程序适用于第一张 SIM 卡。但是当有人调用他的第二张 SIM 卡时,我们的应用程序不会被调用。
我有一个带预览的文件输入。 这是笔 Codepen 我想强制高度,我无法理解我该怎么做。我想将此组件的高度固定为 300px(示例),我还需要保持加载图像的正确纵横比,用灰色背景填充空白。现在我保持宽
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 6年前关闭。 Improve this qu
我正在使用此代码访问 SD card : import os from os.path import join from jnius import autoclass #from android.pe
我正在为数据记录设备编写固件。它以 20 Hz 的频率从传感器读取数据并将数据写入 SD 卡。但是,向SD卡写入数据的时间并不一致(大约200-300 ms)。因此,一种解决方案是以一致的速率将数据写
我正在使用以下代码将视频放到网站上,但是在垂直方向上,手机屏幕上只能看到视频的左半部分 我不是网络开发人员。有人可以告诉我确切的内容吗,如何使其正确放置在手机屏幕上? 是在youtube iframe
我正在使用 Vuetify 1.5 和 Vuetify 网格系统来设置我的布局。现在我有一个组件 HelloWorld我将其导入到我的 Parent 中成分。我已经在我的 HelloWorld 中设置
我使用 python 制作了一个简单的二十一点游戏。我制作了游戏的其余部分,但我正在努力放入 ASCII 卡,所以这只是代码的一小部分。我尝试将 * len(phand) 放在附加行的末尾。虽然这确实
我正在使用玩家卡设置 Twitter 卡。它可以在预览工具中运行,但文档说它需要在“twitter.com 现代桌面浏览器? native iOs 和 Android Twitter 应用程序?mob
任何旧的 GSM 兼容 SIM 卡(3G USIM 的奖励)。 我想我需要一些硬件?谁能为业余爱好者推荐一些便宜的东西,以及一些更专业的东西? 我认为会有一个带有硬件的 API 的完整文档,所以也许这
我使用 python 制作了一个简单的二十一点游戏。我制作了游戏的其余部分,但我正在努力放入 ASCII 卡,所以这只是代码的一小部分。我尝试将 * len(phand) 放在附加行的末尾。虽然这确实
我记得前一段时间读到有 cpu 卡供系统添加额外的处理能力来进行大规模并行化。任何人都有这方面的经验和任何资源来研究项目的硬件和软件方面吗?这项技术是否不如传统集群?它更注重功率吗? 最佳答案 有两个
我检查外部存储是否已安装并且可用于读/写,然后从中读取。我使用的是确切的官方 Android 示例代码 ( from here )。 它说外部存储未安装。 getExternalFilesDir(nu
在 Android 2.1 及更低版本中,Android 应用程序可以请求下载到 SD 卡上吗?另外我想知道应用程序是否可以请求一些包含视频的文件夹下载到 SD 卡上?以及如何做到这一点? 提前致谢。
我们编写了一个 Windows 设备驱动程序来访问我们的自定义 PCI 卡。驱动程序使用 CreateFile 获取卡的句柄。 我们最近在一次安装中遇到了问题,卡似乎停止工作了。我们尝试更换卡(更换似
有些新设备(例如 Samsung Galaxy)带有两个 SD 卡。我想知道是否有任何方法可以确定设备是否有两张 SD 卡或一张 SD 卡。谢谢 最佳答案 我认为唯一的方法是使用 检查可用根的列表 F
我正在尝试将文件读/写到 SD 卡。我已经尝试在我的真实手机和 Eclipse 中的模拟器上执行此操作。在这两种设备上,对/mnt/sdcard/或/sdcard 的权限仅为“d--------”,我
我是一名优秀的程序员,十分优秀!