Uahh/ToastFish · info
程序已经在运行了,不能运行两次。\n如果右下角软件已经退出,请在任务管理器中结束ToastFish任务。
Error message
程序已经在运行了,不能运行两次。\n如果右下角软件已经退出,请在任务管理器中结束ToastFish任务。
What it means
In Form_Load (View/ToastFish.xaml.cs:105), called from the MainWindow constructor, the app derives its own executable name and calls Process.GetProcessesByName; if more than one process with that name exists, it concludes a second instance was started and shows this MessageBox before closing the current window. This is a single-instance guard meant to prevent duplicate tray icons and conflicting SQLite access — the second launch is intentionally terminated.
Solutions
- Do nothing extra: the current (duplicate) instance closes itself. Use the already-running instance's tray icon.
- If no live instance is visible, open Task Manager, end the ToastFish task as the dialog instructs, then relaunch.
- Run "taskkill /IM ToastFish.exe /F" (adjust to the exe name) to clear stale/hung instances, then start the app once.
- Check Startup entries (Task Manager > Startup, shell:startup) and remove duplicates so only one auto-start exists.
- Prefer a named Mutex single-instance check over process-name counting in code, since name-based detection misfires with renamed copies.
Example fix
// before
if (processes.Length > 1) { MessageBox.Show("程序已经在运行了..."); this.Close(); }
// after
private static Mutex _mutex;
_mutex = new Mutex(true, "ToastFish.SingleInstance", out bool createdNew);
if (!createdNew) { MessageBox.Show("程序已经在运行了,不能运行两次。"); this.Close(); return; } Defensive patterns
Strategy: validation
Validate before calling
// check for an existing instance before initializing UI
using var mutex = new Mutex(true, "ToastFish.SingleInstance", out bool createdNew);
if (!createdNew)
{
System.Windows.Forms.MessageBox.Show("程序已经在运行了,不能运行两次。\n如果右下角软件已经退出,请在任务管理器中结束ToastFish任务。", "提示");
return; // abort startup
} Try / catch
try
{
// single-instance check in Program.Main / Form_Load
}
catch (Exception ex)
{
// process enumeration can fail under restricted environments
System.Diagnostics.Debug.WriteLine($"single-instance check failed: {ex.Message}");
} Prevention
- Remember that closing the window does not exit the app — check the system tray first.
- Avoid double-adding the exe to Startup entries.
- Use a named Mutex instead of Process.GetProcessesByName for reliable single-instance enforcement.
- If a previous instance hangs, kill it via Task Manager or taskkill before relaunching.
When it happens
Trigger: Launching ToastFish.exe while another instance is already running (tray icon still alive after window was 'closed'), or when a stale process with the same executable name is running (e.g. a hung instance, a renamed copy, or the app started twice at login).
Common situations: User clicks the exe again thinking the app exited because the window closed while the tray process persists; two shortcuts in the Startup folder; app pinned and also auto-started; a frozen previous instance that must be killed via Task Manager as the message itself instructs; running a copied/renamed exe that collides with the original name.
Related errors
- 检测到您未安装日语语音包,请去“设置”->“时间和语言”->“语音”->“添加语音”中安装日本语,以免影响正常使用。
- ex.Message
- ex.Message, "Excel read error"
- 导入失败,Excel格式不正确或Excel文件损坏
- 卡题出错!
AI-assisted analysis of Uahh/ToastFish@2508784a66 (2026-09-15).
Data as JSON: /api/errors/8c828bf0a244308d.
Report an issue: GitHub.
Appendix: source
Thrown at View/ToastFish.xaml.cs:105
break;
default:
break;
}
}
private void Form_Load()
{
//获取当前活动进程的模块名称
string moduleName = Process.GetCurrentProcess().MainModule.ModuleName;
//返回指定路径字符串的文件名
string processName = System.IO.Path.GetFileNameWithoutExtension(moduleName);
//根据文件名创建进程资源数组
Process[] processes = Process.GetProcessesByName(processName);
//如果该数组长度大于1,说明多次运行
if (processes.Length > 1)
{
System.Windows.Forms.MessageBox.Show("程序已经在运行了,不能运行两次。\n如果右下角软件已经退出,请在任务管理器中结束ToastFish任务。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);//弹出提示信息
this.Close();//关闭当前窗体
}
}
private void SetNotifyIcon()
{
Vm.notifyIcon = new NotifyIcon();
Vm.notifyIcon.Text = "ToastFish";
System.Drawing.Icon icon = IconChika.chika16;
Vm.notifyIcon.Icon = icon;
Vm.notifyIcon.Visible = true;
Vm.notifyIcon.DoubleClick += Begin_Click;
//Vm.notifyIcon.DoubleClick += NotifyIconDoubleClick;
}
public void PlayMute()
{View on GitHub (pinned to 2508784a66)