|
I use the FileSystemWatcher class to monitor a directory for new files.
The directory is usually empty, then i would paste some files in the directory. The files can range anywhere from 1 file to hundreds.
I have a process delay between each event call so as to avoid a sharing violation cause sometimes the event gets triggered but the file is not totally finished saving. For this delay i do:
int x = 0;
while (x<=60000000)
{
int delay = COnvert.ToInt32(x);
x++;
}
What tends to happen for a reason that i am attempting to figure out is say i paste 100 files in there. It may get stuck on the 30th file. I delete the files after i am done with them, so there would be say 70 files from the 100 that i dumped in there left in the folder. So it processed 30 but is stuck somewhere.
Is there something else that i should be aware of when using FIleSytemWatcher?
|
|
|
|
|
Hi,
I don't know why you're having this problem but i know when i tried using the FileSystemWatcher for a similar project(i was downloading in to the folder) i had problems in determining when the file would be completly downloaded.
I solved it in the end but i think it might have been the long-way around.
is it possible for me to send you the source ? That way it might give you an idea for a workaround. (I've just tried describing what i did and i can't really explain it. I'm pretty new to all of this.)
|
|
|
|
|
Sure... Send when you can...
|
|
|
|
|
Why are you performing such a strange busy wait? That's completely useless IMO.
If you really have to wait you should at least use Thread.Sleep so that your application doesn't burn CPU cycles needlessly.
In order to find out if a file has been written completely, I'm using a mechanism that's working reliably so far (written from memory, so no guarantees):
public void WaitForFileCompletion(string path, int maxwait)
{
int wait = 0;
while (true)
{
try
{
FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.None);
fs.Close();
fs.Dispose();
return;
}
catch (IOException)
{
wait += 100;
Thread.Sleep(100);
if (wait > maxwait)
throw new ApplicationException("Timeout reached waiting for completion of file.");
}
}
}
The idea is to open the file exclusively. If another application is still busy writing to the file, this will fail. As soon as opening the file succeeds you can be sure it's been written completely.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hello,
I'm trying to develop an Web or Windows application that will scan text files provided by clients for non-ASCII characters and either remove them or highlight them so I can then replace them with the ASCII equivalent. The text files (generlaly consisting of columns that are tab or comma-delimited) can range from 10 rows to several thousand rows in length.
Can somebody suggest a code approach (C# or even VB.NET) or a link that will assist? I've been doing a great deal of searching on this site and others but have been unable to find a good example.
Thanks,
Kosh
|
|
|
|
|
If you open the file as an ASCII file, all bytes that does not represent an ASCII code (i.e. all codes >= 128) will be replaced with question marks.
What are those non-ASCII "characters", and why are they in the file? Are they characters in some other encoding, and why don't you read the file using that encoding, then?
---
single minded; short sighted; long gone;
|
|
|
|
|
I took the Brain Bench test and was asked this question. I thin the answer should be 0,30,30 but it wasn't listed. What am I doing wrong?
public static void Main() {
Coordinates c1 = new Coordinates();
Coordinates c2 = new Coordinates();
int x = 30;
c1.X = 30;
c2.X = 30;
Test(ref c1, c2, x);
Console.WriteLine("C1.X=" + c1.X.ToString() + ", C2.X=" +
c2.X.ToString() + ", X=" + x.ToString());
Console.Read();
}
public static void Test(ref Coordinates Coord1, Coordinates Coord2, int
X) {
Coord1 = new Coordinates();
Coord2 = new Coordinates();
Coord1.X = 0;
Coord2.X = 0;
X = 0;
}
What is the console output for the above sample code?
Choice 1
C1.X=30, C2.X=30, X=30
Choice 2
C1.X=30, C2.X=0, X=00
Choice 3
C1.X=0, C2.X=0, X=30
Choice 4
C1.X=0, C2.X=0, X=0
Thanks in advance for you help
|
|
|
|
|
brsecu wrote: What am I doing wrong?
Nothing. You are right, whether Coordinates is a class or a struct, it is 0,30,30
|
|
|
|
|
The answer is Choice 3 (0,0,30) if Coordinates is a class, or your answer if Coordinates is a Struct
ALL classes in C# are reference types so regardless if you use the ref keyword or not, they are passed by reference. If Coordinates is a struct instead of a Class then the first parameter is passed by reference and the other 2 are passed by value.
|
|
|
|
|
Nope. Just run the code, and you will see the result is 0,30,30 whether Coordinates is a struct or a class.
The Test() method replaces both Coordinates by new ones, however only the first one makes it back to the caller, thanks to the ref keyword; the second Coordinates is just local to Test().
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
|
What? Are you asking how to convert a bitmap image into a GraphicsPath? You can't.
|
|
|
|
|
So if I have a Trackbar with GraphicsPath as a Tracker , I can't put an Image as GraphicsPath ?
Is there a dll or CustomControl that I can skin with him a TrackBar in WinForm ?
|
|
|
|
|
Epsilone3 wrote: So if I have a Trackbar with GraphicsPath as a Tracker
Uhhh...what? Your subject line suggested you were trying to convert a bitmap image into a GraphicsPath, which is possible, but with great difficulty.
Epsilone3 wrote: I can't put an Image as GraphicsPath ?
No.
Epsilone3 wrote: Is there a dll or CustomControl that I can skin with him a TrackBar in WinForm ?
I think you're asking if there is a way to skin the TrakBar? Not that I know of. You'd probably have to search for a control library that offers one, or write one yourself.
|
|
|
|
|
You asked the reverse twice ( and got the same answer twice, once from me ). It seems to me that you're missing something fundamental here. A path is vector information and a bitmap is raster information. Going vector to raster is easy, the reverse, not so much. You can do it, but expect to spend a long, long time working on it. Expect to end up with something complex enough that it would be salable as a product on it's own. You'd need to find lines in your bitmap, and convert them to paths. Of course, a graphics path cannot recreate a complex bitmap, at least not in a viable way.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thank Christain I miss you last replay.don't got notify mail about her.
Are you know any way ( dll ) CustomControl to Skin TrackBar ?
|
|
|
|
|
I'm sure at least one exists on Code Project as an article, yes.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hello everyone,
I am using the following code to resize the Row of a DataGridView to display the entire data in the row.
<br />
for (int i = 0; i < this.dataGridView3.Rows.Count; i++)<br />
{<br />
this.dataGridView3.AutoResizeRow(i);<br />
}
I was wondering how I can change the size back to what it was before it is AutoResized?
Thank you very much for your help and have a great day.
Khoramdin
|
|
|
|
|
How about saving the Size property value of the grid before you call AutoResizeRow?
|
|
|
|
|
Hi
i have a C# 2005 and oracle 9i database
i was install client component for the .NET from oracle 9i
but when i try to run the program he give me an error message "Need Client Component version x.x.x" where x is some number i do not remember it then
i was install client component for the .NET from oracle 10g
but he give me an error message "Can not Resolove TNS name" ?
how i can solve this problem ?????
|
|
|
|
|
Hey there,
slightly puzzled here. You mention two errors. "Need component ... " and "TNS resolving .. "
There reason why I'm confused is that the TNS resolution error cannot occur unless you've established a proper connection to the host, regardless it's local or remote. And to establish a successful connection you need the Oracle Client Binary referenced in your code. If you've referenced the Oracle Client , the DataAdapter will then use that particular Library. I cannot comment on why it would give the "Need Client .." error, as it seems almost impossible to me.
Basically all you need to do is copy the Oracle DLL to your /Release or /Debug directory and add that DLL as a reference.
As for your "Cannot resolve TNS name" you need to know a little bit about how Oracle works. An Oracle TNS name is basically an entry pointing in the TNSNAMES.ORA file that points to a particular oracle database instance. You might want to check that and set it up. Once this configuration is done you can use the ODBC Administrator to add an Oracle DSN. In the Oracle ODBC Driver Configuration window, in the TNS Name Service text box, you can enter the net service name as you entered it in the setup , or you can enter the fully qualified net service name as it appears in the tnsnames.ora file.
I personally think it's not really an error in your code but merely a configuration mistake in setting up Oracle or the DSN.
Hope this helped.
Cheers
|
|
|
|
|
I need to pass struct MyStruct to another assembly. Please help me and share the code also (if possible).
Thx
A
|
|
|
|
|
I'm not sure what you mean
Foo(MyStruct)
only two letters away from being an asset
|
|
|
|
|
Ok for example
1) I have one assemble say A where i have struct "Mystruct" as
struct Mystruct(
int i;
int j;}
2)Now i am consuming method of another assembly in assembly A
dim myobj as new MyObj
myobj.Calc()
Now calc expects structure ...So how i can pass it?
A
|
|
|
|
|
As long as the assembly B has a reference to Assembly A, for MyStruct
myobj.Calc(struct)
What are finding difficult about this?
only two letters away from being an asset
|
|
|
|