|
I'm working on an FTP client, and using sockets to receive data from a server. When the server sends any data back to the application, I have to wait before the application repsonds. I'd like to starts the transfer for the data in a new thread if possible, leaving the rest of the app free to respond to the user and not just show an hourglass. Is this possible? I'm unsure how to get the data back from the thread.
<br />
Socket socket = openSocket();<br />
SendCommand("MLSD");<br />
if(statusCode != 125 && statusCode != 150) {<br />
LogText = "Error opening connection\n";<br />
return;<br />
}<br />
DateTime timeOutDate = DateTime.Now.AddSeconds(timeOut);<br />
bldBuffer.Remove(0, bldBuffer.Length);<br />
while(DateTime.Now < timeOutDate) {<br />
int bytes = socket.Receive(buffer, buffer.Length, 0);<br />
bldBuffer.Append(Encoding.ASCII.GetString(buffer, 0, bytes));<br />
if(bytes < buffer.Length) {<br />
break;<br />
}<br />
}<br />
socket.Close();<br />
OpenSocket() creates a new socket to the server, and SendCommand() send the specified command over the control connection. The application works, it's just that I have to wait for it to respond.
Thanks for any input.
|
|
|
|
|
Is there some reason you are not using the classes in System.Net namespace that implement the FTP protocol?Echilon wrote: I'd like to starts the transfer for the data in a new thread if possible
Look at the BackgroundWorker or something. It's in the toolbox you can just drop it on your form. There now you are all prepared to do multi-threaded development.
led mike
|
|
|
|
|
I couldn't find performance Explorer in visual studio 2005/2008 Professional. I did search on google they are saying it's in Tool menu but in my version there isn't any. Can somebody help me to locate it. Thanks
|
|
|
|
|
My understanding ( could certainly be wrong ) is that you need a Team edition[^] to get that tool
led mike
|
|
|
|
|
Your understanding is not wrong.
|
|
|
|
|
I was right for once! Did you mark your calendar?
led mike
|
|
|
|
|
led mike wrote: I was right for once! Did you mark your calendar?
Consider it marked.
|
|
|
|
|
If you insist: For the remainder of the year, march fourth will be remembered as the day
led mike got it right...
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
I am working on a C# .net application and need a point in the right direction. Or a Shove if you would rather.
This application should allow the users to upload a .pdf file and then insert it into a mySQL database. I really need some help on the objects that I would need to use to get there.
I have used the openfiledialog to browse and find the file but that is all. I am sort of lost at this point.
These .pdf files will be saved in database as blobs.
Any point in the right direction would be greatly appreciated.
|
|
|
|
|
Well there are like thousands of articles and blog entries on the internet, and probably some on this site about storing blobs in databases.
ASP.NET has a control in the Visual Studio Toolbox for uploading files. I would bet like a cup of coffee that Microsoft has hidden some sample code for using it in the documentation of the control, sneaky bastards!
led mike
|
|
|
|
|
I am sure there are a ton of examples of implementing the control but the trick is which control. Which is the best fit for what I am needing to do?
i.e. allow users to browse for a .pdf, then take that .pdf and insert it into a mySQL database.
Is it openfiledialog ???
The answer you gave could work for any question. Go read the documentation is basically all you said.
Thanks!
|
|
|
|
|
Derrick.greer wrote: Is it openfiledialog ???
Well I may be confused at this point. Your first post said:
Derrick.greer wrote: This application should allow the users to upload a .pdf file
"Uploading Files" is generally used to discuss client server file transfer of the file. I therefore assumed you were doing an ASP.NET Web application. So perhaps you could define your project to clear this up?
led mike
|
|
|
|
|
Here is what I would like to do.
1)I would like the application to allow the user to browse for a .pdf file.
2)I would then like to take that selected file and insert it into a mySQL table.
I was able to get the browse functionality working using the OpenfileDialog but i do not know where to go from there. I basically have a path to the file but nothing else.
Sorry for the confusion that my post caused and thank you for your help.
|
|
|
|
|
So this is a Windows Forms application, a desktop application?
Derrick.greer wrote: 2)I would then like to take that selected file and insert it into a mySQL table.
Where is this database? Is it on the same machine? How are database connections created?
As I said in my first post there are tons of database articles right here on CodeProject for storing blobs in Databases.
If it takes more than 3 posts for you to provide adequate information about your project requirements/architecture that pertain to your questions I will have lost all interest in helping you.
led mike
|
|
|
|
|
Derrick.greer wrote: The answer you gave could work for any question. Go read the documentation is basically all you said.
It's generally very good advice. You'd be surprised at how many questions we answer where the poster could have answered it themself with a 2 minute session reading the manuals.
|
|
|
|
|
led mike wrote: sneaky bastards!
yeah, they're like that!
Dave
|
|
|
|
|
Hey Guys,
Maybe I'm missing something. I thought you could set the ListView where the user can drag items from WITHIN and drop them into other items. The only thing I've been able to do drag objects from without the listview. The functionality should be indentical to a structure like: "My Documents".
Can anybody give a heads up on how to implement this feature?
Thanks
Richard
If you could rent a programmer a hour and a half for a dollar and a half, how much would he charge for 10 hours?
|
|
|
|
|
programmingAddict wrote: I thought you could set the ListView
Are you working through a sample or tutorial? Which one?
If not, you should be as well as using the documentation for ListView of course.
led mike
|
|
|
|
|
I have read that using the registry is out and one should use XML files for storing configuration data on an application.
By using the registry I can hide and prevent the deletion of configuration data - so what is the advantage of using XML in this case, other than learning how to code XML file structures?
My question is really more a case of why use XML in this instance as opposed to the registry?
I ask this a a complete ignoramus in the area of XML
You always pass failure on the way to success.
modified on Tuesday, March 4, 2008 3:07 PM
|
|
|
|
|
GuyThiebaut wrote: By using the registry I can hide and prevent the deletion of configuration data
Really? How do you do that?
led mike
|
|
|
|
|
Okay - let's put it this way, an XML file sitting in the the application folder can be deleted by deleting the folder.
By storing data in the registry the average user of my product, who will probably not even know what the registry is, is only likely to delete the registry entries if they cover their machine in napalm and fire a cruise missile at it.
You always pass failure on the way to success.
modified on Tuesday, March 4, 2008 3:06 PM
|
|
|
|
|
Well I'm certainly not going to argue with that logic so I suggest you just forget about XML and use the registry. You might even consider removing the 'X' 'M' and 'L' keys from your keyboard.
led mike
|
|
|
|
|
Thanks.
Have a nice day
You always pass failure on the way to success.
|
|
|
|
|
GuyThiebaut wrote: in the the application folder
Then don't put it there. I use
C:\Documents and Settings\All Users\Application Data
or similar to hold such things. You can even set the Hidden attribute if you like. I have found that the file remains even after an uninstall of the app.
|
|
|
|
|
The registry can be edited just as easily (probably easier to the general user because of it's tree structure) as an xml file.
In case of a hard drive/OS failure, it's pretty diffucult, and sometimes impossible, to retrieve data from the registry, but because an xml file is local, it's easy to get access to for restoration purposes.
If your app is ever used on Vista, the registry works differently from previous windows versions (unless you want to bother your users with UAC prompts everytime they launch it), so it's not guarenteed to have consistant data across users even if storing in HKLM.
My advice is XML in System.Environment.SpecialFolder.CommonApplicationData + "/YourAppName/"
Dave
|
|
|
|