richtextbox 사용하다 문제점


현재 파일 LoadFile () 해서 copy text 

다른파일 load file() 해서 붙여넣기 


> 해당과정이 매끄럽지 못하다.

1) Loadfile의 format에 따라 될때 안될때 발생

- PlainText의 경우 현재 load된 상태에서 copy / paste 이후 다른 파일 Load해서 클립보드에 있는 내용 paste 정상동작

                         현재 load된 상태에서 copy 이후           다른 파일 load해서 클립보드에 있는 내용 paste 동작안됨.

- 하나의 파일내에서 paste는 정상동작.


2) UnicodePlainText는 정상동작.


c# naudio 로 같은 wave play 시 두번째 재생시 access error 발생


how to dispose ?



하지만 Naudio는 한 폼 안에서 한 개의 파일만 재생할 수 있었다.


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading;

using System.Collections.Concurrent;

namespace cs_blocking_collection

{

    public class Recv

    {

        int threadCount;

        public int ThreadCount { get { return threadCount; } }

        Thread RecvT1;

        Thread RecvT2;

        private BlockingCollection<string> myBC;

        public BlockingCollection<string> RecvBC { get { return myBC; } }

        public Recv()

        {

            myBC = new BlockingCollection<string>();

            RecvT1 = new Thread(new ThreadStart(WokrerMethod));

            RecvT2 = new Thread(new ThreadStart(WokrerMethod));

            threadCount = 2;

            RecvT1.Start();

            RecvT2.Start();

        }

        private void WokrerMethod()

        {

            string s;

            while (true)

            {

                myBC.TryTake(out s, -1);

                if (s == null)

                {

                    Console.WriteLine("Error s is NULL.");

                }

                else if (s != "end")

                {

                    Console.WriteLine

                    ("Thread ID : {0}, Message : {1}", Thread.CurrentThread.ManagedThreadId, s);

                }

                else

                {

                    break;

                }

            }

        }

        public void JoinAll()

        {

            RecvT1.Join();

            RecvT2.Join();

            myBC.Dispose();

        }

    }

    public class Sender

    {

        Recv recv;

        public Sender(Recv r)

        {

            recv = r;

        }

        public void End()

        {

            for (int i = 0; i < recv.ThreadCount; i++)

            {

                recv.RecvBC.TryAdd("end", -1);

            }

            recv.JoinAll();

        }

        public void SendMessage(string s)

        {

            recv.RecvBC.TryAdd(s, -1);

        }

    }

    class Program

    {

        static void Main(string[] args)

        {

            Recv recv = new Recv();

            Sender sender = new Sender(recv);

            for (int i = 0; i < 1000; i++)

            {

                sender.SendMessage(string.Format("Send {0}", i));

            }

            Console.WriteLine("Completed sending message.");

            sender.End();

        }

    }

}

+ Recent posts