|
That is essentially equivalent to the first part of the solution I was talking about. And yes, they do achieve the same result, but you end up throwing exceptions (which are costly for performance), if you just used Thread.Sleep.
I would add that if you were to have more than one file that you're specifically watching for, it looks like his implementation would produce a timer for each. The code I have derives from the FileSystemWatcher and uses the buffer I was talking about earlier to produce the desired result. But, that code should suffice for the most part. Email me if you would want to see the code I have.
|
|
|
|
|
hey andrew... i have done the following:
bool ok = false;<br />
do<br />
{<br />
try<br />
{<br />
File.Move(e.FullPath, e.FullPath);<br />
ok = true;<br />
}<br />
catch<br />
{<br />
Thread.Sleep(1000); }<br />
} while(!ok);
it`s working, but the program sleeps more than expected.
i can`t figure out exactly why. i have put the code in the event file system watcher event handler, so `e` refers to System.IO.FileSystemEventArgs.
any improvements?
|
|
|
|
|
Well, its because you're moving the file back into its same location and firing the event again I assume from the FileSystemWatcher. Then, because you're doing that within the event handler, it causes it to repeat the process forever.
I would first ask you this:
1) Are you attempting to monitor only one file at most?
2) Will the file be modified across a network potentially?
If the file is being updated across a network, you can quickly get numerous events called due to the fact that the file is written in chunks and each chunk fires off an event.
3) Are you attempting to move the file into another location, which will not produce an event?
The FileSystemWatcher has an internal buffer, which if too many events occur within a set amount of time, it will be overrun. Meaning, you'll lose events that you should have received. The best way to avoid this is to fire off another thread (ThreadPool works great here) to handle the job. If what you're doing is pretty minimal within the event handler or you're not handling too many files at a time, this should not be an issue. But I just wanted to make you aware of that problem.
|
|
|
|
|
I am having a strange problem that I have been unable to solve.
Basically, I am doing a DllImport on an unmanaged DLL that I have written, called "config.dll". This DLL is a bunch of C code compiled under a project in VS2005. This is all in a seperate solution.
When I place the DllImport into my C# project, it works fine as long as the config.dll is located in a different folder than the one the C# project is running from (and the DLLImport statement points to the other folder). I have also tried hardcoding the path of the DllImport statement to the directory of the C# project, either through "c:\\test\\config.dll" or ".\\config.dll", and these both give the same result as just "config.dll".
My failing DllImport:
[DllImport("config.dll", CallingConvention=CallingConvention.Cdecl)]
My working DllImport:
[DllImport("c:\\otherdir\\config.dll", CallingConvention=CallingConvention.Cdecl)]
The exception I get is (xxx.dll is the c# project):
An unhandled exception of type 'System.BadImageFormatException' occurred in xxx.dll
Additional information: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
Any help or things for me to check would be appreciated!
Thanks,
David
|
|
|
|
|
I would guess that the dll has been corrupted, i.e. the hashes of the dll don't match up.
|
|
|
|
|
I found the issue - it wasn't a corrupted DLL - rather the DLL I am importing is dependent on other DLLs and one of those DLLs had the same name as one of the DLLs in my application. When I changed my DLL's name, lo and behold, the problem went away.
Thanks for the idea.
|
|
|
|
|
I'm currently porting an application that I wrote over to GTK#. However I'm having a slight issue in deploying it. I chose GTK# because it is licensed under the LGPL ( http://gtk-sharp.sourceforge.net/ ). However the runtime installer shows both the GPL and the LGPL when I install it. It also installs (but doesn't display at install time) a file containing the MIT license.
Because of this I was wondering if there was a way I can include GTK# with my application in it's own subdirectory. I believe I can do that without violating the LGPL license, but I'm not sure how to go about doing that. If anyone can point me in the right direction I would appreciate it.
|
|
|
|
|
Given an array of objects what would be the C# equivalent of the SQL statement:
"select A,B,C from someTable order by B,C"?
Specifically I have a list of objects and I need to group them by more then 1 property, is there a generic solution to this problem that I can reuse in the future?
Thank You
|
|
|
|
|
Put them into a SortedList<> and make the key the properties you want sorted by.
|
|
|
|
|
Can you please elaborate on this? As far as I know SortedList is key/value(s) only. See example below. The grouped list id like returned by B,C would return obj 0, obj 2, obj 1
obj[] objs
obj[0].A = 1
obj[0].B = 2
obj[0].C = 2
obj[1].A = 3
obj[1].B = 3
obj[1].C = 5
obj[3].A = 3
obj[3].B = 2
obj[3].C = 1
|
|
|
|
|
You can also set the IComparer for a SortedList - so you can write whatever comparer you like.
----------------------------
Be excellent to each other
EasiReports[ ^] My free reporting component for WinForms.
|
|
|
|
|
Thing[] things = manager.GetThings();
private SortedList<string, object> list = new SortedList<string, object>();
foreach ( Thing item in things )
{
list.Add( item.B.ToString()+item.C.ToString(), item);
}
Now when you do your populate, you will end up with the list sorted by the values of B+C as you requested.
Sometimes you just have to think outside the square to see the rectangle.
|
|
|
|
|
I have a Function that returns searched criteria into an array. Every 6 elements of that array is one record for that customer. I am wanting to parse this data into a listView for better reading. So every 6 elements should be one row for that listView. Below i have this and it gets the first element for each record.
string[] dataArray;
dataArray = uni.ReadList();
length = dataArray.Length;
if (length > 0 && length % 6 == 0)
{
for (i = 0; i < length; i += 6)
{
listView1.Items.Add(dataArray[i]);
}
}
What i am having problems with is adding the other 5 elements to the listview in the other 5 colums.
Could someone help me out please?
Thanks in Advance
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
You need following code.
ListViewItem item = listView1.Items.Add(dataArray[i]);
item.SubItems.Add(dataArray[i+1]);
item.SubItems.Add(dataArray[i+2]);
|
|
|
|
|
for (int i = 0; i < length; i += 6)
{
<code>ListViewItem itm = listView1.Items.Add(dataArray[i]);
for (int i2 = i+1; i2 < i+6; i2 ++)
{
itm.SubItems.Add(dataArray[i2]);
}</code>
}
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
I have 4 classes (Class 1-4). Classes 2 and 3 are children of class 1. I need both class 2 and 3 to call on methods from class 4. I've looked at the base method but I can't seem to make it do what I want it to.
I could just make an instance of class 4 in both classes 1 and 2, however I'm trying to avoid it.
Any ideas, or should I just call the two instances of class 4?
Oh, and Class 1 is a static class.
Dave
|
|
|
|
|
Make the instance of class 4 a member of class 1, with protected access, so that class 2 and 3 can access it.
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
Muntyness wrote: or should I just call the two instances of class 4?
Not possible to answer definitively without more context, but that is a reasonable approach. Another might be a class 1.2 that encapsulates the use of class 4 and then class 2 and 3 derive from class 1.2 rather than from class 1.
led mike
|
|
|
|
|
Can you put class outline, it will make easy to understand what exactly you want....
|
|
|
|
|
M Aamir Maniar: This will probably make you more confused, but....
Static Class 1
|
--> Class 2 + Class 3
then
Class 2 + Class 3
|
---->Class 4 method
So class 1 on creates both class 2 and 3.
Then a method in either 2 or 3 calls a method in 4.
MP (2): Its a static, so it wont let me create a protected instance of class 4.
led mike: You suggestion might work, but I'm going to try to avoid it.
(I only want class 4 as either children of 2 and 3 or a seperate instance from them, because of what it does)
Dave
|
|
|
|
|
Then go with Marilyn Manson's reply
|
|
|
|
|
If class 4 is static, then there is nothing stopping you from using that method.
Assume everything below is all in the same namespace.
public static class Calculator
{
public static int Compute(param obj[] parms){...}
}
public class One
{
Class2 clas2 = new Class2();
Class3 clas3 = new Class3();
....
clas2.Consume();
clas3.Consume();
}
public class Class2
{
public void COnsume()
{
Calculator.Compute(parms);
}
}
public class Class3
{
public void Consume()
{
Calculator.Compute(otherParms);
}
}
|
|
|
|
|
Hi,
How to get the height and width of a window which has a scrollbar both horizontal and vertical.
Thanks
Subramanya
|
|
|
|
|
Subramanyahs wrote: How to get the height and width of a window which has a scrollbar both horizontal and vertical.
The height and width should be the same regardless of what is inside the window. However if you are trying figure the height and width of the inner area just subtract the width of the scrollbars from the window's width and height.
=====Brain melting code=====
static int Sqrt(int x){ if (x<0) throw new ArgumentOutOfRangeException(); int temp, y=0, b=0x8000, bshft=15, v=x; do { if (v>=(temp=(y<<1)+b<<bshft--)) { y+=b; v-=temp; } } while ((b>>=1)>0); return y; :omg:
====TSI TLFL EEOOLHTG=====
^^^^^^^^^^^^^^^^^
Decode that and you will win.;P
============Hint===========
cout << "33 20 57 4F 52 44 53 62 63 6B 77 6F 72 64 73";
|
|
|
|
|
I am new to C# & .Net.
I have an application that have some .exe files. It used to execute with the help of some Dll's. .exe files used to execute only if these dlls and exe files are in the same folder.
The problem is that when i am trying to create a window installer for my application, it used to create all dlls and exe files in program(start) menu. whereas i just wants to have the exe in the program menu, not the dll's. For e.g if we use the setup of winamp or any other application, on clicking the setup, it installs and only exe will be there in the program menu. No supporting files will be there.
hope it may give you an idea of what am i trying to ask....
thanks in advance
Praveen Raghuvanshi
Software Engineer,
Wins Infotek Pvt. LTd.
Technopark, Trivandrum
India.
|
|
|
|