static int _m_EndWrite(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); System.IO.FileStream gen_to_be_invoked = (System.IO.FileStream)translator.FastGetCSObj(L, 1); { System.IAsyncResult _asyncResult = (System.IAsyncResult)translator.GetObject(L, 2, typeof(System.IAsyncResult)); gen_to_be_invoked.EndWrite(_asyncResult); return(0); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
public override void EndWrite(IAsyncResult asyncResult) { InternalFileStream.EndWrite(asyncResult); }
private void SaveToFileAsync(string fileToSave, FileTreeItem fti) { try { var fs = new System.IO.FileStream(fileToSave, System.IO.FileMode.Create); var src = fti.GetDataStream(); const int CHUNK_SIZE = 1024 * 10; //kilobytes byte[] buffer = new byte[CHUNK_SIZE]; Action <Exception> Done = (exc) => { if (exc != null) { this.Dispatcher.BeginInvoke(new Action(() => Utils.UIHelper.DefaultErrHandling(exc))); } fs.Close(); src.Close(); }; AsyncCallback CallbackExpr = null; CallbackExpr = (IAsyncResult readResult) => { try { int read = src.EndRead(readResult); if (read > 0) { fs.BeginWrite(buffer, 0, read, writeResult => { try { fs.EndWrite(writeResult); src.BeginRead(buffer, 0, buffer.Length, CallbackExpr, null); } catch (Exception exc) { Done(exc); } }, null); } else { Done(null); } } catch (Exception exc) { Done(exc); } }; // Here we go! src.BeginRead(buffer, 0, buffer.Length, CallbackExpr, null); } catch (Exception exc) { Utils.UIHelper.DefaultErrHandling(exc); } }