Click here to Skip to main content
15,900,108 members
Home / Discussions / C#
   

C#

 
GeneralRe: How can I dictate the position of the run prompt? Pin
turbosupramk328-Apr-14 11:02
turbosupramk328-Apr-14 11:02 
GeneralRe: How can I dictate the position of the run prompt? Pin
Dave Kreskowiak28-Apr-14 13:43
mveDave Kreskowiak28-Apr-14 13:43 
GeneralRe: How can I dictate the position of the run prompt? Pin
turbosupramk328-Apr-14 15:26
turbosupramk328-Apr-14 15:26 
GeneralRe: How can I dictate the position of the run prompt? Pin
turbosupramk329-Apr-14 2:35
turbosupramk329-Apr-14 2:35 
GeneralRe: How can I dictate the position of the run prompt? Pin
Alan N29-Apr-14 6:14
Alan N29-Apr-14 6:14 
GeneralRe: How can I dictate the position of the run prompt? Pin
turbosupramk329-Apr-14 9:14
turbosupramk329-Apr-14 9:14 
GeneralRe: How can I dictate the position of the run prompt? Pin
Dave Kreskowiak29-Apr-14 10:36
mveDave Kreskowiak29-Apr-14 10:36 
GeneralRe: How can I dictate the position of the run prompt? Pin
turbosupramk330-Apr-14 6:02
turbosupramk330-Apr-14 6:02 
GeneralRe: How can I dictate the position of the run prompt? Pin
Dave Kreskowiak30-Apr-14 8:16
mveDave Kreskowiak30-Apr-14 8:16 
GeneralRe: How can I dictate the position of the run prompt? Pin
turbosupramk330-Apr-14 8:49
turbosupramk330-Apr-14 8:49 
GeneralRe: How can I dictate the position of the run prompt? Pin
Alan N29-Apr-14 11:25
Alan N29-Apr-14 11:25 
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 

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.