public void Update() { WinApiImport.QueryPerformanceCounter(out PerfomanceCount); WinApiImport.QueryPerformanceFrequency(out Frequency); WinApiImport.GetSystemTimeAsFileTime(out var fileTime); SystemFileAsFileTime = ((ulong)fileTime.dwLowDateTime << 32) + (ulong)fileTime.dwHighDateTime; }
public static string Read(string name) { var hEvent = WinApiImport.CreateEvent(new LPSECURITY_ATTRIBUTES(), false, false, name); if (hEvent == IntPtr.Zero) { return(string.Empty); } var ov = new OVERLAPPED { hEvent = hEvent }; var info = WinApiImport.GetMailslotInfo(slots[name], 0, out var size, out var _, 0); if (info == IntPtr.Zero || size <= 0) { return(string.Empty); } var msgPointer = Marshal.AllocHGlobal(size); var res = WinApiImport.ReadFile(slots[name], msgPointer, size, out var read, ref ov); if (res == IntPtr.Zero) { return(string.Empty); } var message = Marshal.PtrToStringAnsi(msgPointer); return(message); }
public static void Close(string name) { var slot = slots[name]; WinApiImport.CloseHandle(slot); slots.Remove(name); files.Remove(name); }
public static void Wait(IntPtr semaphore) { #if DEBUG return; #endif while (WinApiImport.WaitForSingleObject(semaphore, int.MaxValue) != 0) { } }
public static IntPtr Create(string name, int limit) { #if DEBUG return(IntPtr.Zero); #endif var options = new LPSECURITY_ATTRIBUTES(); var semaphore = WinApiImport.CreateSemaphore(ref options, limit, limit, name); return(semaphore); }
public static bool Create(string name) { var slot = WinApiImport.CreateMailslot(SlotPrefix + name, 0, int.MaxValue, new LPSECURITY_ATTRIBUTES()); if (slot == invalidHandle) { return(false); } slots[name] = slot; return(true); }
public static bool Write(string name, string message) { var file = GetFile(name); if (file == invalidHandle) { return(false); } var size = (message.Length + 1) * sizeof(char); var res = WinApiImport.WriteFile(file, message, size, out var written, new OVERLAPPED()); if (res == IntPtr.Zero) { return(false); } return(true); }
private static IntPtr GetFile(string name) { if (files.ContainsKey(name)) { return(files[name]); } var file = WinApiImport.CreateFile( SlotPrefix + name, WinApiImport.GenericWriteAccess, WinApiImport.FileShareRead, new LPSECURITY_ATTRIBUTES(), (int)FileMode.Open, WinApiImport.FileAttributeNormal, IntPtr.Zero); if (file != invalidHandle) { files[name] = file; } return(file); }
public static void Release(IntPtr semaphore) { #if !DEBUG WinApiImport.ReleaseSemaphore(semaphore, 1, IntPtr.Zero); #endif }
public static void Close(IntPtr semaphore) { #if !DEBUG WinApiImport.CloseHandle(semaphore); #endif }