我的问题是关于URL协议.
我已经注册了一个名为mcm的URL协议,但我注意到每次从任何Web浏览器运行它都会创建一个新的应用程序实例.有没有办法在已经运行的实例中处理协议请求?
例如,当uTorrent使用torrent协议时,它会立即处理请求,而无需再次运行应用程序.我真的找不到任何有趣的东西,所以我在这里问...
这是我用来注册协议的代码:
private static void RegisterUrlProtocol()
{
UnregisterUrlProtocol();
RegistryKey rKey = Registry.ClassesRoot.OpenSubKey(UrlProtocol, true);
if (rKey == null)
{
rKey = Registry.ClassesRoot.CreateSubKey(UrlProtocol);
rKey.SetValue("", "URL: MazCraft Protocol");
rKey.SetValue("URL Protocol", "");
rKey = rKey.CreateSubKey(@"shell\open\command");
rKey.SetValue("", "\"" + Application.ExecutablePath + "\" %1");
}
if (rKey != null)
{
rKey.Close();
}
}
Run Code Online (Sandbox Code Playgroud)
以及读取参数的代码:
private static bool CheckForProtocolMessage()
{
string[] arguments = Environment.GetCommandLineArgs();
if (arguments.Length > 1)
{
string[] args = arguments[1].Split(':');
args[1] = args[1].Replace("//", "");
if (args[0].Trim().ToUpper() == "MCM" …Run Code Online (Sandbox Code Playgroud)