internal static SRes Thread_Create(out CThread p, Action func, string threadName) { p = new CThread(); p._thread = new System.Threading.Thread(delegate() { func(); }); p._thread.Name = threadName; p._thread.Start(); return(TSZ("Thread_Create")); }
public void Dispose() { // update to cleanup session this.Abort(); ActiveSessions = null; QueuedSessions = null; WriterManager = null; }
internal static void Thread_Close(ref CThread p) { if (p != null) { p._thread.Join(); } p = null; }
public CSession(Int32 SessionIndex_, TDownloadChangedFunc DownloadChangedFunc_, TDownloadCompletedFunc DownloadCompletedFunc_) { _SessionIndex = SessionIndex_; _DownloadChangedFunc = DownloadChangedFunc_; _DownloadCompletedFunc = DownloadCompletedFunc_; _WorkerThread = new CThread(_Worker); _WebClient.DownloadProgressChanged += _DownloadProgressChangedCallback; _WebClient.DownloadDataCompleted += _DownloadDataCompletedCallback; }
// Encapsulates the logic to connect to the server public static void ConnectToServer() { // Tries to connect to the server, listening at localhost, port 8080 try { Console.WriteLine("Looking for server on IP Address: {0}\nPort: {1}", "127.0.0.1", 8080); Console.WriteLine("Trying to connect to the server...\n"); // Creates a new TCP Client with IP: localhost and Port: 8080 (TCP) client = new TcpClient("127.0.0.1", 8080); ins = new StreamReader(client.GetStream()); outs = new StreamWriter(client.GetStream()); // Flushes buffer after every call to StreamWriter.Write() outs.AutoFlush = true; } // Catches exception if the connection to the server fails catch (Exception e) { Console.WriteLine("Error: Could not stablish connection to the server"); Console.WriteLine(e.Message); Console.ReadLine(); } // Checks that the client creation was correct and throws and exception in case // an error occurs during its creation if (client != null && outs != null && ins != null) { try { CThread chat = new CThread(client, ins, outs); Thread ctThread = new Thread(chat.Run); ctThread.Start(); // Keeps reading messages from the server while it's open while (!chat.closed) { string msg = Console.ReadLine().Trim(); outs.WriteLine(msg); } // Closes the connection when it receives the signal to close outs.Close(); ins.Close(); client.Close(); } catch (Exception e) { // Catches exception and prints the error to console Console.WriteLine("Error: Could not create client"); Console.WriteLine(e.Message); Console.ReadLine(); } } }
public void Stop(enumThreadID id) { CThread result = null; if (m_list.TryGetValue(id, out result)) { result.Stop(); m_list.Remove(id); } }
public CSessionManager() { // start session manager thread ActiveSessions = new List <CSession> { }; QueuedSessions = new List <CSession> { }; WriterManager = new CThread() { Worker = new Thread(new ThreadStart(ManageSessions)) }; Core.ThreadManager.Add(WriterManager); }
internal static SRes Thread_Wait(CThread p) { #if BUILD_PORTABLE p._task.GetAwaiter().GetResult(); #else p._thread.Join(); #endif #if !DISABLE_TRACE Trace.MatchThreadWait(p._thread); #endif return(TSZ("Thread_Wait")); }
internal static SRes Thread_Create(out CThread p, Action func, string threadName) { p = new CThread(); #if !DISABLE_TRACE p._thread = Trace.MatchThreadStart(func); #elif BUILD_PORTABLE p._task = System.Threading.Tasks.Task.Run(func); #else p._thread = new System.Threading.Thread(delegate() { func(); }); p._thread.Name = threadName; p._thread.Start(); #endif return(TSZ("Thread_Create")); }
public void Dispose() { // update to cleanup session // Log.Write(" : CSessionManager (disposed)", Log.Verbosity.Everything); Terminated = true; foreach (CSession session in CompletedSessions) { session.Disconnect(); } this.Abort(); ActiveSessions = null; QueuedSessions = null; SessionManager = null; }
internal static SRes Thread_Create(out CThread p, Action func, string threadName) { p = new CThread(); #if !DISABLE_TRACE p._thread = Trace.MatchThreadStart(func); #elif BUILD_PORTABLE p._task = System.Threading.Tasks.Task.Run(func); #else p._thread = new System.Threading.Thread(delegate () { func(); }); p._thread.Name = threadName; p._thread.Start(); #endif return TSZ("Thread_Create"); }
internal static SRes Thread_Wait(CThread p) { #if BUILD_PORTABLE p._task.GetAwaiter().GetResult(); #else p._thread.Join(); #endif #if !DISABLE_TRACE Trace.MatchThreadWait(p._thread); #endif return TSZ("Thread_Wait"); }
internal static void Thread_Close(ref CThread p) { if (p != null) { #if !DISABLE_TRACE Trace.MatchThreadClose(p._thread); #elif BUILD_PORTABLE p._task.GetAwaiter().GetResult(); #else p._thread.Join(); #endif } p = null; }
public CSessionManager() { // Log.Write(" : CSessionManager (initialized)", Log.Verbosity.Everything); // start session manager thread CompletedSessions = new List <CSession> { }; ActiveSessions = new List <CSession> { }; QueuedSessions = new List <CSession> { }; SessionManager = new CThread() { Worker = new Thread(new ThreadStart(ManageSessions)) }; Core.ThreadManager.Add(SessionManager); }
public void DoWork() { Completed = false; Started = true; string uid = CFunctions.GenerateUID(); string starttime = CFunctions.GetDateTime(0); Log.Write("[Threading] Starting thread (" + uid + ") to generate database output to " + Outfile.ToLower(), Log.Verbosity.Everything); CThread.Types threadtype = new CThread.Types(CThread.Types.Unmanaged); CDatabaseExporter de = new CDatabaseExporter(); CThread exporter = new CThread() { Type = threadtype, Worker = new Thread(delegate() { de.Export(this, ref _DBConn, DiscoveredSites, DiscoveredServers); }), Id = uid }; Core.ThreadManager.Add(exporter); }
public void PushMsg(enumThreadID id, IThreadMsg msg) { #if UNITY_IPHONE int idIntVal = (int)id; if ((int)enumThreadID.enumThread_Res >= idIntVal) { CMonoThreadSimulator resultIOS = null; if (!m_listIOS.TryGetValue(id, out resultIOS)) { GameObject webSimulator = new GameObject("WebMonoSimulator" + ((int)id).ToString()); resultIOS = webSimulator.AddComponent <CMonoThreadSimulator>(); GameObject.DontDestroyOnLoad(webSimulator); m_listIOS.Add(id, resultIOS); } resultIOS.push(msg as CThreadMsgWebGet); return; } #endif CThread result = null; if (m_list.TryGetValue(id, out result)) { result.PushMsg(msg); } else { result = new CThread(); m_list.Add(id, result); result.Start(); result.PushMsg(msg); } }
internal static SRes Thread_Wait(CThread p) { p._thread.Join(); return(TSZ("Thread_Wait")); }
internal static bool Thread_WasCreated(CThread p) { return(p != null); }
internal static void Thread_Construct(out CThread p) { p = null; }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="request"></param> /// <param name="addBufferSize"></param> /// <param name="thread"></param> /// <param name="parameters"></param> /// <param name="o"></param> /// <returns></returns> byte[] ServerOnMessage(TcpClient client, byte[] request, out bool addBufferSize, CThread thread, object parameters, object o) { addBufferSize = true; Console.WriteLine($"SERVER RECEIVED: {Encoding.UTF8.GetString(request)}"); //return Encoding.UTF8.GetBytes("That's fine"); server.Send1WayNotification(Encoding.UTF8.GetBytes("That's fine"), addBufferSize, "TEST", o); return(null); }
private Dictionary <string, CService> CheckServiceIfRequired(Dictionary <string, CService> _ServicesToCheck) { List <CThread> ScanTasks = new List <CThread> { }; Dictionary <string, CService> _CheckedServers = new Dictionary <string, CService> { }; _ServerPortScanResults = new HashSet <string> { }; foreach (CService s in _ServicesToCheck.Values) { int port = 0; string search = null; CNetwork.Protocols protocol = null; if (s.Type == CServiceType.VCenterServer) { port = 80; search = "VMware vSphere"; protocol = new CNetwork.Protocols(CNetwork.Protocols.HTTP); } if (s.Type == CServiceType.HYVServer || s.Type == CServiceType.SCVMMServer) { port = 135; search = "RPC Endpoint Mapper"; protocol = new CNetwork.Protocols(CNetwork.Protocols.RPC); } if (port > 0) { CThread scan = new CThread() { Worker = new Thread(new ThreadStart(delegate() { DoPortScan(s, port, protocol, search); })) }; ScanTasks.Add(scan); Core.ThreadManager.Add(scan); } else { _CheckedServers.Add(s.Name + ";" + s.Type.ToString(), s); } } bool ScanTaskCompleted = false; do // wait till completed { bool status = true; for (int i = 0; i < ScanTasks.Count; i++) { if (!ScanTasks[i].Completed) { status = false; } } ScanTaskCompleted = status; Thread.Sleep(COptions.Session_Thread_Wait); } while (!ScanTaskCompleted); foreach (string s in _ServerPortScanResults) { string name = s.Split(';')[0]; string type = s.Split(';')[1]; _CheckedServers.Add(name + ";" + type, _ServicesToCheck[name + ";" + type]); } return(_CheckedServers); }
internal static void Thread_Close(ref CThread p) { if (p != null) { #if !DISABLE_TRACE Trace.MatchThreadClose(p._thread); #else p._thread.Join(); #endif } p = null; }
internal static SRes Thread_Wait(CThread p) { p._thread.Join(); #if !DISABLE_TRACE Trace.MatchThreadWait(p._thread); #endif return TSZ("Thread_Wait"); }
internal static bool Thread_WasCreated(CThread p) { return p != null; }