如何只制作一个Windows小工具实例(Windows 7中的侧边栏)? [英] How do I make only one instance of windows gadget(sidebar in windows 7)?

查看:179
本文介绍了如何只制作一个Windows小工具实例(Windows 7中的侧边栏)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个Windows小工具(Windows 7中的侧边栏),它不是一个Windows应用程序,但它是一个像粘滞便笺一样的侧边栏。我无法限制小工具的实例。我只想要一次运行一个实例而不再运行。





注意:小工具是Windows SideBars,类似于便利贴或桌面上的日历。



我尝试过:



我不知道为了达到这个目的必须做些什么。

I am currently working on a windows gadget(sidebar in windows 7), its not a windows application, but it is a sidebar like sticky notes. I am unable to limit the instances of the gadget. I just want one instance running at a time and no more.


Note: Gadgets are Windows SideBars that are similar to sticky notes or the calendar on the desktop.

What I have tried:

I have no clue what has to be done in order to achieve this.

推荐答案

在C#中你可以使用 Mutex

In C# you can use a Mutex:
public static void Main()
	{
		bool createdNew;
		var mutex = new Mutex(false, "SingletonWinAppMutex", out createdNew);

		if (!createdNew)
		{
			MessageBox.Show(@"You can only start one gadget instance !");
			Application.Exit();
			return;
		}
...


Javascript:也许这个 live-mutex API 会对你:

Node.js更好的互斥锁--Alex Mills - 中等 [ ^ ]

有点长的啰嗦,但在文章底部附近有一个例子。
Javascript: maybe this live-mutex API will be of interest to you:
A better mutex for Node.js – Alex Mills – Medium[^]
It's a bit long winded but somewhere near the bottom of the article there's an example.


这篇关于如何只制作一个Windows小工具实例(Windows 7中的侧边栏)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆