|
Hello everyone,
I am developing a module in C#.net3.0 on windows XP. I am downloading a file from the ftp server in asynchronous mode. Before the download completes, i am doing another Async download of another file by again creating the object of WebClient with the same name.
I am handling the downloadFileCompleteEventHandler(Object sender, AsyncEventHandler e). Now i want to see which file download has raised this event handler. For this, i think i have to send file name as parameter to this downloadFileCompleteEventHandler(Object sender, AsyncEventHandler e) method.
My code snippet is as follows:
private void FtpToStagingServer(String spotID, Int32 Ctr)
{
//DOWNLOADING TO LOCAL DATABASE SERVER
WebClient ccftp = new WebClient();
try
{
//Download from Clearcut Server
ccftp.Credentials = new NetworkCredential(Username, Password);
Uri CcFtp = new Uri("ftp://"+HostIp+"/Assets/"+spotID+".mpg");
ccftp.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(ccftp_DownloadFileCompleted);
ccftp.DownloadFileAsync(CcFtp, "C:\\AWS_FilesDownloaded\\"+spotID+".mpg");
tAssetId = spotID;
}
catch (WebException wes)
{
}
catch (Exception es)
{
}
// throw new Exception("The method or operation is not implemented.");
}
void ccftp_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
//Transfer the downloaded asset from Clearcut server to the Staging server/
MessageBox.Show(" Ftp from clearcut to local drive completed");
WebClient ssFtp = new WebClient();
try
{
ssFtp.Credentials = new NetworkCredential("abc", "abc123");
ssFtp.UploadFileCompleted += new UploadFileCompletedEventHandler(ssFtp_UploadFileCompleted);
ssFtp.UploadFileAsync(new Uri("ftp://somehostIpwith path/"+ tAssetId+".mpg"), "C:\\AWS_cc_download\\" + tAssetId + ".mpg");
}
catch (WebException wes)
{
}
catch (Exception es)
{
}
//throw new Exception("The method or operation is not implemented.");
}
I am trying it by taking a temporary global variable to hold the filname, but it is of no use.
Could you please help me in this.. by giving required c#.net links or sample code.
Thank you
Anee
|
|
|
|
|
Hello everyone,
I am working on C#.net(3.0) in windows XP platform. I have a two different servers with FTP in it.
I am developing a module in the above technology, in which, without i have to transfer a file from one FTP server to another FTP server, without using the local system.
Now, i am downloading required file from the FTp-server1 to local system and then, from the local system i am uploading it to the other Ftp-server2. But, i want to do file transfer directly from the ftp-server1 to the ftp-server2, without using local system.
could you please give me some hint or the required links that can help me in doing this.
Any help is greatly appreciable.
Thanks
Anee
|
|
|
|
|
suppose in my win application there is a variable which holds some text data or image binary data. i want to print that text or image by printer. so please tell me how can i send instruction to a printer as a result printer can print my text data or image data.please help me with sample code.
tbhattacharjee
|
|
|
|
|
Hello tbhattacharjee,
You would need to work with Win32 spooler functions. The link below shows how you can use them:
http://support.microsoft.com/kb/322091
Regards,
Dave
Dave Traister
Software Engineer
ComponentOne LLC
www.ComponentOne.com
|
|
|
|
|
suppose i have create one win application there is one SDI form and that form has a one button and may have other controls too.so i want that when i will click on that button then the inner portion of the form along with all the controls placed on the form will be save as.gif image in a file system excluding form's title bar.
please also tell me in case of MDI how to save look of the SDI form just clicking on the MDI menu like same way above one.
please help me with sample code in VS2003 version.
tbhattacharjee
|
|
|
|
|
Hello Friends,
I am Developing an C#.NET windows application in this i require to save text written on textbox or label as a image it may be in any format like JPG, BMP.
Means whatever text written in textbox will as it is in image format.
|
|
|
|
|
1.) Create a Bitmap with the dimension of your output-control.
2.) Create a Graphics-object for this bitmap
3.) Use the Graphics-object, the font of your control and the text of this control to render the text to the Graphics-object via it's DrawString method.
4.) Use the .Save Method of the Bitmap to save it to the desired image file
|
|
|
|
|
Hello Sir,
Thanks for your suggestion but i am new to .NEt so please could you provide me tha code for this solution
Thanks
|
|
|
|
|
Can two dlls with same name but from different author be referenced at the same time?
|
|
|
|
|
Hello
i guess so.
but they should have a diffrent NameSpace
|
|
|
|
|
Friends,
I am navigating inside GAC folder using command prompt i.e on my machine: c:\Windows\Assembly\GAC
I have three versions of .NET installed in my machine. So i am expecting three different System.dll files in the respective folders.
But when im issuing *dir* command to look inside system directory, there is only one folder visible:
Directory of C:\Windows\assembly\GAC\System
12/12/2007 11:42 AM <DIR> .
12/12/2007 11:42 AM <DIR> ..
12/12/2007 11:42 AM <DIR> 1.0.5000.0__b77a5c561934e089
0 File(s) 0 bytes
3 Dir(s) 119,704,276,992 bytes free i.e version 1.0.5000.0 of System.dll is there. My question is that where are the other versions of this dll and why their respective folders are not there ?
Imtiaz
|
|
|
|
|
Hi,
AFAIK the .NET system dll's are located elsewhere; I found System.dll in
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 and others
so I would say they either get added to the GAC virtually, or they are not in the GAC at all.
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.
|
|
|
|
|
Ha, yeah, I just did a GACUTIL /L to list the contents.
System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
is the only entry for System.
|
|
|
|
|
Is it wrong to use an instance property to hold the instance of a thread?
Example code of what I mean:
using System;
using System.Threading;
using System.Collections;
using System.Windows.Forms;
using System.IO;
using newThreads;
namespace newThreads
{
class newThread
{
private uint i;
newThread()
{
i=0;
}
newThread(uint I)
{
i=I;
}
newThread(int I)
{
i=Convert.ToUInt32(I);
}
private volatile bool bExit = false;
public void threadMethod()
{
while (!bExit)
{
++i;
Thread.Sleep(1500);
}
}
public void ResetThread()
{
i = 0;
public void ThreadExit()
{
bExit = false;
}
}
}
namespace newApp
{
public class winFormApp : System.Windows.Forms.Form
{
private newThreads _newThread;
public newThreads newThread
{
get
{
return _newThread;
}
set
{
_newThread = value;
}
}
public winFormApp()
{
InitializeComponent();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
}
#endregion
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
using (winFormApp mainForm = new winFormApp())
{
mainForm.newThread = new newThreads.newThread();
Thread newThreadID = new Thread(mainForm.newThread.threadMethod);
newThreadID.Start();
while (!newThreadID.IsAlive)
{
Thread.Sleep(1);
}
Application.Run(mainForm);
mainForm.newThread.ThreadExit();
newThreadID.Join(new TimeSpan(0, 0, 3));
if (newThreadID.IsAlive)
{
newThreadID.Abort();
File.AppendAllText("newApp.log", "Forcefully killed new thread, join() timed out." + Environment.NewLine, System.Text.Encoding.ASCII);
}
}
return;
}
}
}
Only reason for this is I wish to call other methods (besides the exit one) in the thread via the winForm instance, and this is the first way I thought of on how to get a hold of the thread's instance inside the winFrom. Well, without starting the thread inside the winForm, but that was ruled out because the thread needs to do stuff before the form loads.
The problem is I don't like the looks of it, but at the same time it does what I'm needing to do. I can't think of a reason not to do it, so I'm asking for other solution suggestions / comments on mine.
Also would like to know if this could be considered bad practice...
|
|
|
|
|
Hi,
I have several comments on your code:
1.
identifiers are case-sensitive, but having two variables differ in casing only is a bad idea, so I do
not recommend your line i=I; . For one, you will confuse yourself, and furthermore if you
read this aloud to someone, he won't understand you at all.
Remark: nevertheless, people often have properties and local values that differ only by the casing of
their first letter, so you could have public int Something {set {something=value;}}
which is generally accepted and understood by everyone.
2.
I don't like the newThread names (both namespace and class) very much. Everything is new at first, and
gets old by itself, so I would avoid having new in such names. I would suggest "MyThread", "TestThread",
"SomeSpecialThreadDoingSoAndSo", whatever best describes it.
It may seem irrelevant, but picking appropriate names will help you as soon as you (or a team of people)
get involved in bigger projects, so I recommend taking care of this from day one.
3.
The line Thread.Sleep(1); will not behave exactly as you expect, it will typically sleep for 10 or
more milliseconds; you may want to read my timers article.
4.
To answer your specific question: the sequence
- call constructor (mainForm = new winFormApp)
- set some properties (mainForm.newThread =)
- now call a method to start something happening (Application.Run(mainForm)
is quite common, and in fact it is most often better than using a constructor or a method with a lot of
parameters.
However, I don't particularly like the idea of passing a thread to some class.
If the class is about a thread experiment, I would put all the thread related code inside the class, it
does not help having half of it in the class, and half outside.
If the class needs a thread for its own purposes (making the thread irrelevant to the outside), I would
definitely put all the thread stuff inside).
5.
I didn't like the newThreadID = new Thread(...); line much, i.e. the variable's name
should be newThread, not newThreadID, since it really is a thread (a threadID is a number identifying
a thread at the kernel level, a Thread is an instance of the Thread class).
6.
In general it is not a good idea to kill/abort a thread; it is a drastic measure to terminate it immediately,
with the disadvantage that it potentially leaves its objects in an unknown state (files open, resources
locked, whatever). So it should be avoided if possible. Here the intent seems to be to allow the app
to exit, which any foreground thread would prevent. The solution is to make it a background thread,
hence newThread.IsBackground=true; before newThread.Start();
Doing so will cause Windows to kill the background threads as soon as all foreground threads are done,
so there too the object states may be indetermined, but at exit this is of lesser importance, since
Windows will always try and clean up at exit too.
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.
|
|
|
|
|
Thanks for the comments and input.
Responses:
1. & 2.
Comments based off the simplified example code. Sorry if I wasted your time analizing the code rather than the "general" design.
3.
timing doesn't matter, just a delay to prevent 100% CPU / thread lock if for some unknown reason the thread doesn't start right away. Which would be a case 1 out of 1000000 or more... I just need to know if it is active and running before I start up the form else trouble might start brewing
4.
You seem to have come to the same conclusion I did but with minor differences
A. I'm not passing the thread to the form but storing it's class instance in a property, which is diffrent / unheard of to me.
B. I'm more worried about what happens if form get thrown to the GC before the thread finishes, because the class instance will stay with all data intact until the GC junks it.
I've used setup properties before, which is why I thought of this. I do think this is better than running a method to get the device handles, save them to a public static ArrayList (yuck!), start the form, via onload event start processing the devices based off the public static ArrayList in a new timer thread, and then onclosing event to close the devices handles and wait for the last timer thread to die.
5.
see 1. & 2.
6.
Considering that the thread is holding handles to USB devices, I can't make it in the background. If the thread can't finish and exit within 3 seconds (~16-18 loops in the thread) after calling join() and setting the exit flag. Then it is soft locked and wouldn't matter if I killed it. Since the app is closing anyway it's ok to just junk it and the USB port handle will timeout at ~750ms via my driver. The problem here is it's better to allow the thread to finish for it might be witting to e2 on the device. Which is bad if you save to the the device and close the form before it is 100% written.
|
|
|
|
|
Hi Spacix,
you're welcome.
3.
To yield CPU cycles for the duration of the system tick, a Thread.Sleep(0) is recommended.
4,6.
You didn't tell about USB and EE before, I now see why you did what you did.
I'm still not convinced there is a need to do it this way tho, AFAIK running timers (i.e. not
stopped/disabled) and threads (foreground and background ones) remain active even if you don't
have any live references to them any more (except that the last foreground thread reaching
its exit will cause app exit). For timers it is well documented; for threads I don't know
if/where it is stated explicitly, the only thing I noticed is there is no Thread.Dispose()
so I expect the "physical" thread to live on independent of the "logical" Thread object.
7.
I would suggest you create a "myUsbDevice" class that encapsulates all relevant code,
including the thread stuff, and the dont-interrupt-EE-writing logic. You might give it an IsBusy()
or a WaitTillDone() method and give your form a FormClosing event, where you wait until
myUsbDevice.IsBusy() returns false or 3 seconds have elasped (easiest is to read DateTime.Now
in a yielding loop).
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 recently noticed that some of the code I wrote does not work as I expected; Namely, when attempting to reflectively set the value of a property on a value type, nothing happens (because it is passed to SetValue by value instead of by reference). I am wondering if there is a way to make the following set the value of the property UniqueId.
public struct foo {
...
public int UniqueId {
get { return m_Id; }
set { m_Id = value; }
}
...
}
public foo CreateFoo() {
foo rval = new foo();
PropertyInfo pi = typeof(foo).GetProperty("UniqueId");
if (pi != null) {
pi.SetValue(rval, 7, null);
}
return rval;
} I know that in the example, there is no need for reflection. However, the example is just an extreme simplification of my code to illustrate the problem. Once again, my question is, "Is there some way to modify the line 'pi.SetValue(rval, 7, null)' such that rval.UniqueId will equal 7 after the reflective call". Not using reflection to set the value cannot be implemented given the current code. Thanks in advance,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Got it! I have to box the object myself as follows:
public foo CreateFoo() {
object rval = new foo();
PropertyInfo pi = typeof(foo).GetProperty("UniqueId");
if (pi != null)
pi.SetValue(rval, 7, null);
return (foo)rval;
} Hope this helps someone else!
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
And that worked? I tried
foo rval = new foo();
object item = rval ;
pi.SetValue( item, 7, null) ;
and it was no better.
I just tried your way and I see it works.
|
|
|
|
|
Huh, that is odd. The documentation doesn't say it won't work for structs, the closest statement to that is:
"
To use the SetValue method, first get a Type object that represents the class.
"
Does this mean it only works for classes?
|
|
|
|
|
Well, technically it IS setting the value, the only problem is that it is setting the value on a copy of the struct passed in, so the changes are lost the instant the SetValue method returns. Oh well, at least I got it to work. Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
I was looking for a program that would output to the port and found Levent Saltuklaroglu’s I/O Ports Uncensored - 1 - Controlling LEDs with Parallel Port. It’s a great program, works nice.
I've been playing with the source code he uploaded with it to get a slightly different outcome from some of the buttons. Turns out, I haven't been able to compile it, not even his original code. I get an error message "missing partial modifier on declaration of type 'led.form1'; another partial declaration of this type exists". I was hoping someone could help me with this.
I'm using Microsoft Visual Studio C# 2008 express edition. I've also copy and pasted his code into a new Windowsformapplication1 window.
Is there a better way?
|
|
|
|
|
highly doubtful his project was written in 2008, probably 2003, before partial classes existed. Sounds like VS2008 has created the partial class for control autogenerated code, try just adding the word 'partial' before the word 'class' ( or perhaps after ) and see if it compiles.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi
I have problem with data table in C#.In the code below i have data table which contains some values. "dt" is DataTable object and "dr" is DataRow[] object. when i fire some query on datatable using select method, it returns some datarows which fulfill the expression. And when i modify any column value of datarow like column "ID" it also modifies the values in datatable dt.
Can you tell me why this is happening? I don't want to modify values in datatable dt.
Thank you.
Class prog
{
static void Main(string[] args)
{
dr = dt.Select(expression);
dr[0]["ID"] = 10;
}
}
|
|
|
|
|