Click here to Skip to main content
15,892,005 members
Home / Discussions / C#
   

C#

 
GeneralRe: Efficient Xml reading? Pin
#realJSOP6-Mar-08 10:33
mve#realJSOP6-Mar-08 10:33 
General.NET standard components Pin
Steve Declerck5-Mar-08 3:46
Steve Declerck5-Mar-08 3:46 
GeneralRe: .NET standard components Pin
Xmen Real 5-Mar-08 4:30
professional Xmen Real 5-Mar-08 4:30 
GeneralRe: .NET standard components Pin
Gareth H5-Mar-08 4:34
Gareth H5-Mar-08 4:34 
GeneralRe: .NET standard components Pin
John_Adams5-Mar-08 5:14
John_Adams5-Mar-08 5:14 
GeneralRe: .NET standard components Pin
Pete O'Hanlon5-Mar-08 8:30
mvePete O'Hanlon5-Mar-08 8:30 
GeneralRe: .NET standard components Pin
Steve Declerck5-Mar-08 23:22
Steve Declerck5-Mar-08 23:22 
QuestionThreads and BeginReceive Pin
Echilon5-Mar-08 3:28
Echilon5-Mar-08 3:28 
I'm coding an FTP client in C#, and I'm trying to use System.Net.Socket's BeginReceive method to stop the UI from freezing when receiving data. At present, it works as it should, but whenever there's a transfer in progress (upload/download or directory listing), the UI freezes until it's complete.

I want to use BeginReceive to recive data in a different thread. This is what I have to far:
Two classes - FTP and FrmMain.
In FTP I have a delegate:
<br />
public delegate void DirListDelegate(object sender, ArrayList items);<br />
public event DirListDelegate OnDirListComplete;<br />

The I have three methods:
<br />
    private void OnDataReceived(IAsyncResult asyn) {<br />
    int bytes = dataSocket.EndReceive(asyn);<br />
    bldBuffer.Append(Encoding.ASCII.GetString(buffer, 0, bytes));<br />
    if(bytes < buffer.Length) {<br />
        dataSocket.Close();<br />
        // Trimmed code to process data into "itemsList"<br />
        OnDirListComplete(this, itemsList);<br />
    } else {<br />
        WaitForData();<br />
    }<br />
}<br />
private void WaitForData() {<br />
    dataSocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(OnDataReceived), null);<br />
}<br />
public void ListDir() {<br />
    dataSocket = openSocket();<br />
    //trimmed code to make server initiate transfer ("LIST -al")<br />
<br />
    bldBuffer.Remove(0, bldBuffer.Length);<br />
    WaitForData();<br />
}<br />

Then I call FTP.ListDir() from FrmMain. What should happen is the main program should be free to respond to user clicks etc and not freeze, but it's as though I'm just using Receive instead of BeginReceive.

I'm really stuck on this and I'd appreciate any help. Smile | :)
GeneralRepost ( new member ) Pin
led mike5-Mar-08 4:52
led mike5-Mar-08 4:52 
GeneralWebcontrol inside a webcontrol Pin
ezazazel5-Mar-08 3:26
ezazazel5-Mar-08 3:26 
GeneralRe: Webcontrol inside a webcontrol Pin
Vasudevan Deepak Kumar5-Mar-08 4:34
Vasudevan Deepak Kumar5-Mar-08 4:34 
GeneralRe: Webcontrol inside a webcontrol Pin
ezazazel5-Mar-08 5:01
ezazazel5-Mar-08 5:01 
GeneralRe: Webcontrol inside a webcontrol Pin
ezazazel5-Mar-08 6:28
ezazazel5-Mar-08 6:28 
GeneralDataGridView & DataSet - Updating the DataBase Pin
half-life5-Mar-08 3:23
half-life5-Mar-08 3:23 
QuestionP/Invoking void * - is this the right way? Pin
Luca Leonardo Scorcia5-Mar-08 2:54
professionalLuca Leonardo Scorcia5-Mar-08 2:54 
AnswerRe: P/Invoking void * - is this the right way? Pin
led mike5-Mar-08 4:56
led mike5-Mar-08 4:56 
AnswerRe: P/Invoking void * - is this the right way? Pin
Luc Pattyn5-Mar-08 5:43
sitebuilderLuc Pattyn5-Mar-08 5:43 
GeneralRe: P/Invoking void * - is this the right way? Pin
Luca Leonardo Scorcia5-Mar-08 7:32
professionalLuca Leonardo Scorcia5-Mar-08 7:32 
AnswerRe: P/Invoking void * - is this the right way? Pin
Ernest Laurentin5-Mar-08 5:59
Ernest Laurentin5-Mar-08 5:59 
GeneralInvalidPrinterException when printer is installed and working - only with HP LaserJet 1010 series Pin
Dragan Matic5-Mar-08 2:22
Dragan Matic5-Mar-08 2:22 
GeneralStarting point to Crystal Reports Pin
Harvey Saayman5-Mar-08 2:16
Harvey Saayman5-Mar-08 2:16 
General[Message Deleted] Pin
Krishnaraj Barvathaya B5-Mar-08 0:52
Krishnaraj Barvathaya B5-Mar-08 0:52 
GeneralRe: How to copy files in a folder tree into a single folder Pin
pmarfleet5-Mar-08 1:26
pmarfleet5-Mar-08 1:26 
GeneralRe: How to copy files in a folder tree into a single folder Pin
Krishnaraj Barvathaya B5-Mar-08 5:48
Krishnaraj Barvathaya B5-Mar-08 5:48 
GeneralRe: How to copy files in a folder tree into a single folder Pin
Anthony Mushrow5-Mar-08 6:03
professionalAnthony Mushrow5-Mar-08 6:03 

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.