omidamiry
شنبه 22 مهر 1391, 20:31 عصر
این کد دارای خطاس کی بلده رفع کنه
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Diagnostics;
namespace SingleInstanceTest
{
static class Program
{
[System.Runtime.InteropServices.DllImport(user32.dl l)]
[return System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
public static bool HasPriorInstance()
{
Process currentProcess = Process.GetCurrentProcess();
string fileName = currentProcess.StartInfo.FileName;
foreach (Process process in Process.GetProcessesByName(currentProcess.ProcessN ame))
{
if (process.Id == currentProcess.Id) { continue; }
if (process.StartInfo.FileName != fileName) { continue; }
SetForegroundWindow(process.MainWindowHandle);
return true;
}
return false;
}
[STAThread]
static void Main()
{
if (!HasPriorInstance())
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new Form1());
}
}
}
}
این دو خط رو نمشناسه
[return System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Diagnostics;
namespace SingleInstanceTest
{
static class Program
{
[System.Runtime.InteropServices.DllImport(user32.dl l)]
[return System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
public static bool HasPriorInstance()
{
Process currentProcess = Process.GetCurrentProcess();
string fileName = currentProcess.StartInfo.FileName;
foreach (Process process in Process.GetProcessesByName(currentProcess.ProcessN ame))
{
if (process.Id == currentProcess.Id) { continue; }
if (process.StartInfo.FileName != fileName) { continue; }
SetForegroundWindow(process.MainWindowHandle);
return true;
}
return false;
}
[STAThread]
static void Main()
{
if (!HasPriorInstance())
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new Form1());
}
}
}
}
این دو خط رو نمشناسه
[return System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);