/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> private void Dispose(bool disposing) { // free managed resources if (disposing) { } // free unmanaged resources if (_handle != IntPtr.Zero) { MFPCOMM_ERROR mfpCommError = MFPComm_Uninitialize(_handle); } }
public bool DiscoverAsyncCancel() { if (!IsBusy || IsCancellationPending) { return(true); } MFPCOMM_ERROR mfpCommError = MFPComm_CancelDiscovery(_handle); if (mfpCommError == MFPCOMM_ERROR.MFPCOMM_OK) { _discoveryWorker.CancelAsync(); return(true); } return(false); }
private void DiscoveryDoWork(object sender, DoWorkEventArgs e) { DiscoveryWorkerArgument argument = e.Argument as DiscoveryWorkerArgument; MFPCOMM_ERROR mfpCommError = MFPCOMM_ERROR.MFPCOMM_OK; switch (argument.Type) { case DiscoverMfp.All: mfpCommError = MFPComm_DiscoverMFPs(_handle); break; case DiscoverMfp.InRange: mfpCommError = MFPComm_DiscoverMFPRange(_handle, argument.StartMfpIP, argument.EndMfpIP); break; case DiscoverMfp.IP: mfpCommError = MFPComm_DiscoverMFP(_handle, argument.MfpIPorName); break; //case DiscoverMfp.Name: // break; default: return; } switch (mfpCommError) { case MFPCOMM_ERROR.MFPCOMM_OK: while (true) { // Create a struct MFP_T mfp_t = new MFP_T(); // Initialize unmanged memory to hold the struct IntPtr pnt = Marshal.AllocHGlobal(Marshal.SizeOf(mfp_t)); // Copy the struct to unmanaged memory Marshal.StructureToPtr(mfp_t, pnt, false); switch (MFPComm_GetMFP(_handle, ref pnt)) { case MFPCOMM_ERROR.MFPCOMM_FAIL: case MFPCOMM_ERROR.MFPCOMM_FINISHED: Marshal.FreeHGlobal(pnt); return; case MFPCOMM_ERROR.MFPCOMM_WAIT: Marshal.FreeHGlobal(pnt); break; case MFPCOMM_ERROR.MFPCOMM_CONTINUE: MFP_T discoveredMfp = (MFP_T)Marshal.PtrToStructure(pnt, typeof(MFP_T)); RaiseMfpDiscovered(this, new MfpDiscoveredEventArgs(discoveredMfp)); break; } Thread.Sleep(1000); } case MFPCOMM_ERROR.MFPCOMM_FAIL: break; } }