Programing/C# 썸네일형 리스트형 c# 크로스 스레드, 델리게이트 delegate 활용 public ServerMain() { InitializeComponent(); Thread ServerMain = new Thread(Server_MainLoof); ServerMain.Start(); } private void Server_MainLoof() //서버의 메인루프 { CheckForIllegalCrossThreadCalls = false; IPEndPoint ipep = new IPEndPoint(IPAddress.Any, Constants.Server_Port); //서버의 아이피와 객체를 담기위한 객체 ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //서버소켓 생성 .. 더보기 c# 크로스 스레드(CheckForIllegalCrossThreadCalls) // This event handler creates a thread that calls a // Windows Forms control in an unsafe way. private void setTextUnsafeBtn_Click( object sender, EventArgs e) { this.demoThread = new Thread(new ThreadStart(this.ThreadProcUnsafe)); this.demoThread.Start(); } // This method is executed on the worker thread and makes // an unsafe call on the TextBox control. private void ThreadProcUnsafe() { this... 더보기 (C#) Semaphore Release Queue Q = new Queue(); //쓰레드형으로 큐 선언 private void enterRelease() { if (this.Q.Count > 0) //Q카운터가 0보다크면 Release 쓰레드를 풀어줌 { Thread tempThread = this.Q.Dequeue(); lock (tempThread) { Monitor.Pulse(tempThread); } } else { this.enternumber++; } } 큐 카운터가 0보다 크면 tempThread 에 큐에 들어있는 Thread를 받고 Monitor를 이용해 tempThread를 다시 활성하 해준다 그리고 0 이거나 0보다 작으면 enternumber를 1 증가시켜 줍니다. 그리고 저 lock도 동기화 하는 방식인데 저렇게 해야 .. 더보기 (C#) FiFo Semaphore 예전에 설계시간에 FiFo 세마포어를 사용할일이 있어서 만든겁니다. C#에서는 기본적으로 세마포어를 제공해주는데 세마포어에서 Release 해줄때 순차적으로 릴리즈 해주는게 아니라 랜덤으로 나와서 몇일 고생하며 만든 기억 이 나네요~ 잘 쓰시길 바래요 Release 함수는 프로젝트를 열어봐야해서 다음에 시간되면 포스팅 하겠습니다 private void enterWait(object num) { Thread tempThread = null; int number = (int)num; if (enternumber > 0) { enternumber--; return; } else { tempThread = Thread.CurrentThread; this.Q.Enqueue(tempThread); lock (tem.. 더보기 이전 1 다음