Click here to Skip to main content
15,888,610 members
Home / Discussions / C#
   

C#

 
GeneralRe: How can I dictate the position of the run prompt? Pin
turbosupramk330-Apr-14 6:11
turbosupramk330-Apr-14 6:11 
GeneralRe: How can I dictate the position of the run prompt? Pin
Alan N1-May-14 3:12
Alan N1-May-14 3:12 
GeneralRe: How can I dictate the position of the run prompt? Pin
turbosupramk32-May-14 1:46
turbosupramk32-May-14 1:46 
QuestionImplementing transaction in MVC as Attribute Pin
nitin_ion28-Apr-14 0:12
nitin_ion28-Apr-14 0:12 
AnswerRe: Implementing transaction in MVC as Attribute Pin
Dave Kreskowiak28-Apr-14 3:18
mveDave Kreskowiak28-Apr-14 3:18 
GeneralRe: Implementing transaction in MVC as Attribute Pin
nitin_ion28-Apr-14 17:19
nitin_ion28-Apr-14 17:19 
GeneralRe: Implementing transaction in MVC as Attribute Pin
Dave Kreskowiak28-Apr-14 17:55
mveDave Kreskowiak28-Apr-14 17:55 
QuestionHow to use Multithreading in Async Socket Http request Pin
sbmzhcn27-Apr-14 15:22
sbmzhcn27-Apr-14 15:22 
In multi thread, i use async socket , alway An error occurred:
ReceiveCallback Error: System.ObjectDisposedException: 无法访问已释放的对象。

对象名:“System.Net.Sockets.Socket”。

在 System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult, SocketError& errorCode)

在 System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult) ....

This is my code:
C#
private void ReceiveCallback(IAsyncResult ar)
        {
            try
            {
                if (null == ar)
                    return;

                // Retrieve the state object and the client socket 
                // from the asynchronous state object.
                StateObject state = (StateObject)ar.AsyncState;
                Socket client = state.workSocket;

                if (null == state)
                    return;

                // Read data from the remote device.
                int bytesRead = client.EndReceive(ar);

                if (bytesRead > 0)
                {
                    //把接收到的数据写入流中
                    ms.Write(state.buffer, 0, bytesRead);
                    state.sb.Append(Encoding.UTF8.GetString(state.buffer, 0, bytesRead));
                    if (!state.sb.ToString().EndsWith("\r\n\r\n"))
                    {
                        client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                            new AsyncCallback(ReceiveCallback), state);
                    }
                    else
                    {
                        int index = state.sb.ToString().IndexOf("\r\n\r\n", System.StringComparison.Ordinal);
                        int lastclr = state.sb.ToString().LastIndexOf("\r\n", index);
                        string strhex = state.sb.ToString().Substring(lastclr + 2, index - lastclr -2);
                        Int32 hex;
                        if (Int32.TryParse(strhex, System.Globalization.NumberStyles.AllowHexSpecifier, null,
                            out hex))
                        {
                            // All the data has arrived; put it in response.
                            if (state.sb.Length > 1)
                            {
                                Response = state.sb.ToString();
                            }
                            // Signal that all bytes have been received.
                            receiveDone.Set();
                        }
                        else
                        {
                            //client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,new AsyncCallback(ReceiveCallback), state);
                            client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                            ReceiveCallback, state);
                        }
                    }
                    // Get the rest of the data.
                }
                else
                {
                    // All the data has arrived; put it in response.
                    if (state.sb.Length > 1)
                    {
                        Response = state.sb.ToString();
                    }
                    // Signal that all bytes have been received.
                    receiveDone.Set();
                }
            }
            catch (Exception e)
            {
                throw new Exception("ReceiveCallback Error: " + e);
            }
        }


C#
for (int nIndex = 0; nIndex < value; nIndex++)
                    {
                        // check if thread not created or not suspended
                        if (threadsRun[nIndex] == null && ThreadsRunning)
                        {
                            // create new thread
                            threadsRun[nIndex] = new Thread(new ThreadStart(delegate() { ThreadScraper(); }));
                            // set thread name equal to its index
                            threadsRun[nIndex].Name = nIndex.ToString();
                            // start thread working function
                            threadsRun[nIndex].Start();
                        }
                        else
                        {
                            Console.Write("");
                        }
                    }

Questionlooking for a decent book on c# for advanced programmers Pin
Nico Haegens27-Apr-14 1:10
professionalNico Haegens27-Apr-14 1:10 
AnswerRe: looking for a decent book on c# for advanced programmers Pin
Pete O'Hanlon27-Apr-14 1:59
mvePete O'Hanlon27-Apr-14 1:59 
AnswerRe: looking for a decent book on c# for advanced programmers Pin
BillWoodruff27-Apr-14 7:08
professionalBillWoodruff27-Apr-14 7:08 
AnswerRe: looking for a decent book on c# for advanced programmers Pin
jschell27-Apr-14 9:36
jschell27-Apr-14 9:36 
GeneralRe: looking for a decent book on c# for advanced programmers Pin
Ravi Bhavnani28-Apr-14 4:44
professionalRavi Bhavnani28-Apr-14 4:44 
AnswerRe: looking for a decent book on c# for advanced programmers Pin
thatraja27-Apr-14 20:59
professionalthatraja27-Apr-14 20:59 
GeneralRe: looking for a decent book on c# for advanced programmers Pin
Dnyaneshwar@Pune28-Apr-14 0:11
Dnyaneshwar@Pune28-Apr-14 0:11 
GeneralRe: looking for a decent book on c# for advanced programmers Pin
rutja_deore28-Apr-14 0:12
rutja_deore28-Apr-14 0:12 
GeneralRe: looking for a decent book on c# for advanced programmers Pin
thatraja28-Apr-14 4:29
professionalthatraja28-Apr-14 4:29 
AnswerRe: looking for a decent book on c# for advanced programmers Pin
Ravi Bhavnani28-Apr-14 4:43
professionalRavi Bhavnani28-Apr-14 4:43 
QuestionRunning thread to refresh image disable scrollbars in DataGridView Pin
neualex26-Apr-14 5:44
neualex26-Apr-14 5:44 
AnswerRe: Running thread to refresh image disable scrollbars in DataGridView Pin
OriginalGriff26-Apr-14 6:06
mveOriginalGriff26-Apr-14 6:06 
GeneralRe: Running thread to refresh image disable scrollbars in DataGridView Pin
neualex28-Apr-14 3:28
neualex28-Apr-14 3:28 
GeneralRe: Running thread to refresh image disable scrollbars in DataGridView Pin
OriginalGriff28-Apr-14 3:34
mveOriginalGriff28-Apr-14 3:34 
QuestionI got this error on page load my photo gallery page . http://s.codeproject.com/script/Forums/Images/smiley_WTF.gif Pin
300sparta25-Apr-14 23:03
300sparta25-Apr-14 23:03 
AnswerRe: I got this error on page load my photo gallery page . http://s.codeproject.com/script/Forums/Images/smiley_WTF.gif Pin
OriginalGriff25-Apr-14 23:18
mveOriginalGriff25-Apr-14 23:18 
QuestionHow can I change the background color of the part of a ComboBox that is always visible? Pin
arnold_w25-Apr-14 4:34
arnold_w25-Apr-14 4:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.