/// <summary> /// Initializes a new <see cref="AwaitableEvent"/> instance. /// </summary> /// <param name="handle">The handle to the OpenCL event.</param> public AwaitableEvent(IntPtr handle) : base(handle, "AwaitableEvent", true) { // Subscribes to the event callbacks of the OpenCL event, so that a CLR event can be raised EventsNativeApi.SetEventCallback( Handle, (int)CommandExecutionStatus.Queued, Marshal.GetFunctionPointerForDelegate(new AwaitableEventCallback((waitEvent, userData) => OnQueued?.Invoke(this, new EventArgs()))), IntPtr.Zero); EventsNativeApi.SetEventCallback( Handle, (int)CommandExecutionStatus.Submitted, Marshal.GetFunctionPointerForDelegate(new AwaitableEventCallback((waitEvent, userData) => OnSubmitted?.Invoke(this, new EventArgs()))), IntPtr.Zero); EventsNativeApi.SetEventCallback( Handle, (int)CommandExecutionStatus.Running, Marshal.GetFunctionPointerForDelegate(new AwaitableEventCallback((waitEvent, userData) => OnRunning?.Invoke(this, new EventArgs()))), IntPtr.Zero); EventsNativeApi.SetEventCallback( Handle, (int)CommandExecutionStatus.Complete, Marshal.GetFunctionPointerForDelegate(new AwaitableEventCallback((waitEvent, userData) => OnCompleted?.Invoke(this, new EventArgs()))), IntPtr.Zero); }
public async Task Run() { if (State == ActorState.Running) { throw new InvalidOperationException("actor is already running"); } if (State == ActorState.Destroyed) { throw new InvalidOperationException("actor has been destroyed"); } await RunInternal(); State = ActorState.Running; OnRunning?.Invoke(); _logger.LogInformation($"{this.GetType()} started"); }
/// <summary> /// 大数据转换 /// </summary> /// <param name="cnn"></param> /// <param name="tableName"></param> /// <param name="fileName"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public static async Task CSV(ConnectionModel cnn, string tableName, string fileName, CancellationToken cancellationToken = default(CancellationToken)) { OnStart?.Invoke(); var dbObj = DBObjectHelper.GetDBObject(cnn); var reader = dbObj.GetDataReader(cnn.Database, $"select * from {tableName}"); var header = new List <string>(); var filedCount = reader.FieldCount; if (filedCount > 0) { for (int i = 0; i < filedCount; i++) { header.Add(reader.GetName(i)); } } using (StringWriter sw = new StringWriter()) { StringBuilder sb = new StringBuilder(); char c = ','; for (int i = 0; i < filedCount; i++) { sb.Append(header[i] + c); } sb.Append("\r\n"); var rowCount = 1; while (reader.Read()) { rowCount++; for (int j = 0; j < filedCount; j++) { try { sb.Append(ConvertToSaveCell(reader[j])); OnRunning?.Invoke(filedCount * j + rowCount, filedCount * rowCount); } catch { sb.Append(c); } } sb.Append("\r\n"); } sw.Write(Encoding.UTF8.GetString(new byte[] { (byte)0xEF, (byte)0xBB, (byte)0xBF })); sw.Write(sb); using (var fs = File.Open(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) { using (StreamWriter ssw = new StreamWriter(fs)) { await ssw.WriteAsync(sb.ToString()); } } } OnStop?.Invoke(); }