void ThreadLoad_Method(string path, Action <object> onComplete) { if (!FileExists(path)) { onComplete.Invoke(null); return; } object obj = null; BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(path, FileMode.Open, FileAccess.Read); try { obj = bf.Deserialize(file); } catch (Exception e) { Log.Error("Failed to deserialize the following file:\n" + path + "\n\nError:\n" + e.Message); } file.Close(); if (onComplete != null) { MainThreadService.AddMainThreadCallbackFromThread(delegate() { onComplete(obj); }); } }
void ThreadSave_Method(string path, object graph, Action onComplete = null) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(path, FileMode.OpenOrCreate); bf.Serialize(file, graph); file.Close(); MainThreadService.AddMainThreadCallbackFromThread(onComplete); }
public void WriteLine(string text) { if (ThreadUtility.IsMainThread) { WriteLineNow(text); } else { MainThreadService.AddMainThreadCallbackFromThread(() => WriteLineNow(text)); } }
public static void DisplayMessageFromThread(string message) { MainThreadService.AddMainThreadCallbackFromThread(() => DisplayMessage(message)); }