|
|
need to connect .xls files as a database connection...
wat should i install for this purpose????
i'm geetin an error regarding ODBC connectivity...but i did complete installtion of VS2005
|
|
|
|
|
Hi ,
would you help me to add a calculated record in a data grid (select the maximum id value then add 1 & assign the new value to the new row in the datagrid)
thanks,,
|
|
|
|
|
Can't wait to be allowed to download and use .NET 3 here at the office. Hopefully lambda expressions (or something else I'm not thinking of at the moment) will fix the fact that I can't do this:
DateTime dt = new delegate(SomeObject o)
{
int year = Convert.ToInt32(((string)o.Value).Substring(0, 4));
int month = Convert.ToInt32(((string)o.Value).Substring(4, 2));
int day = Convert.ToInt32(((string)o.Value).Substring(6, 2));
return new DateTime(year, month, day);
};
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan
Portland, Oregon, USA
|
|
|
|
|
Jamie, I'm afraid .NET 3 is purely a .NET library extension; C# 3 (which includes lambda expressions) isn't yet released.
However, you can do what you just wrote in C# 2:
delegate TReturn ReturnFunction<TReturn, TArg>(TArg argument);
ReturnFunction<DateTime, SomeObject> method = delegate(SomeObject o)
{
int year = Convert.ToInt32(((string)o.Value).Substring(0, 4));
int month = Convert.ToInt32(((string)o.Value).Substring(4, 2));
int day = Convert.ToInt32(((string)o.Value).Substring(6, 2));
return new DateTime(year, month, day);
};
DateTime dt = method(someObjectInstance);
|
|
|
|
|
Oh, I know it's just an extension. My complaint is this part:
delegate TReturn ReturnFunction<TReturn, TArg>(TArg argument);
This seems like a mute point. If I'm going to write that, THEN write the delegate description, it seems like the ONLY thing gained is not having to call the function something (on the other hand, you still have to name the delegate). To me, it seems as though you're actually doing MORE by using anonymous methods than just writing a helper func, because you have to declare the delegate signature.
Maybe I'm just missing something (which is totally possible). Why would I want to go through the extra typing instead of just declaring a helper func?
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan
Portland, Oregon, USA
|
|
|
|
|
I just have a utility library that contains a bunch of generic delegate declarations. I then use these throughout my code.
With C# 3, System.Query.dll will contain a bunch of generic delegates, allowing you to just use these instead and won't have to declare your own.
And honestly, just a few generic delegates (maybe 4 overloads, each one taking 1 more parameter than the last, and another 4 for return functions) and you never have to write another delegate again.
|
|
|
|
|
Generic delegates? If you don't mind me asking, can you post an example (or email me directly)? I believe you, I'm just really trying to understand the point of these things. They're the one thing about 2.0 that's escaped me thus far.
Either way, thanks for your input, Judah. I appreciate it.
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan
Portland, Oregon, USA
|
|
|
|
|
It's nothing too spectacular; just delegates sitting in some namespace, available to the rest of your code. Thus, your code doesn't have to define custom delegates all over the place; instead, just use a generic one. Here's my (names changed to protect the innocent) file containing several generic delegates[^].
With that file handy, whenever you've got a piece of code that requires a new delegate, instead of defining a new delegate, I just use an existing generic one. Say I need a delegate that returns void and takes 2 strings:
Function<string, string> myFunc = SomeFuncThatTakesTwoStrings;
...
void SomeFuncThatTakesTwoStrings(string first, string second) { ... }
As you can see, no custom delegate declaration required. Easier and more consistent than defining a new delegate each and every time you want to treat a function as a variable. The GenericDelegates file contains definitions for
Function()
Function(T param);
Function(T1 first, T2 second);
...
and so on, all the way up to 6 parameters. I haven't had the need for any more than that, but it's easy to add overloads for more parameters.
I also have ReturnFunction definitions for functions that return something other than void, including the 6 overloads for varying number of parameters.
Again, it isn't anything special; it just removes the burden of having to write custom delegates all over the place. It also allows one's code to be a little more uniform, using the same delegates everywhere rather than class-specific ones.
|
|
|
|
|
Oh, OK. NOW I see what you're getting at. I remember seeing the Function delegate in the System.Query namespace that you mentioned before. I just wasn't remembering at the time. Cool! I like this idea, though the end result, apparently, is that even with .NET 3, I still can't say something like:
DateTime dt = delegate(string dateString){
int year = dateString.SubString(0, 4);
int month = dateString.SubString(4, 2);
int day = dateString.SubString(6, 2);
return new DateTime(year, month, day);
};
which is what I thought Anonymous functions would get us when I first heard of them. Oh well...
Thanks again for the info, Judah!
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan
Portland, Oregon, USA
|
|
|
|
|
Hi folks!
Could some WMI guru please help me with this problem?
I need to find out the model of a USB pen an application is run from.
So far I used WMI to get the Win32_LogicalDisk the application is run from, then the related Win32_DiskPartition and the related Win32_DiskDrive for the logical disk.
This works fine when the app is run with admin rights, returning one partition and one drive.
Unfortunately, when the application is run as a user with limited rights, no disk partitions are reported, so I cannot find out the model of the USB pen.
Does anyone know how to find out this information even for a non-admin user?
Thanks in advance,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hi
Are the 2 pieces of code equivalent in terms of thread safety?
<br />
DateTime Date{<br />
get {<br />
lock (this) {<br />
return date;<br />
}<br />
}<br />
set {<br />
lock (this) {<br />
date = value;<br />
}<br />
}<br />
}<br />
<br />
DateTime Date {<br />
get {<br />
DateTime tempDate;<br />
lock (this) {<br />
tempDate = date;<br />
}<br />
retirm tempDate<br />
}<br />
set {<br />
lock (this) {<br />
date = value;<br />
}<br />
}<br />
}<br />
Because it'd be nice to avoid the extra boilerplate code, and simply return the value.
(In other words I ask whether the return value is copied before or after the finally block)
|
|
|
|
|
When using lock, it releases the lock immediately upon leaving the block, be it from an exception or return even.
The above code (the first snippet) translates to:
DateTime Date
{
get
{
try
{
AcquireLock();
return date;
}
finally
{
ReleaseLock();
}
}
set
{
try
{
AcquireLock();
date = value;
}
finally
{
ReleaseLock();
}
}
}
I forget the actual method underneath the covers it calls to acquire the lock, but that's essentially what it boils down to.
|
|
|
|
|
Hi,
So is the first method Thread Safe?
|
|
|
|
|
Yes. It's thread safe because it releases the lock in the 'finally' block before the control flow exits the block of code. Finally blocks always get executed...
|
|
|
|
|
I have no idea how I can publish my project. (Visual Studio 2005) Who can help me with an example.
|
|
|
|
|
You mean with ClickOnce ?
|
|
|
|
|
Hello all of you!
I have a strange problem and I need help to solve it.
I have a windows application written in C# that sporadically terminates, no exceptions, no error codes, no messages at all. The application starts a new thread which sends information to the windows form via events. The thread uses USB-connected printers to print small paper-labels and a USB-CAN interface.
Is it a thread related error? Deadlock? Stack overflow?
Is it caused by a collision in the USB-interface?
Hopfully, Daniel Carlson
|
|
|
|
|
Do you wait until your Printer thread is finished before terminating your main thread ?
Regards
|
|
|
|
|
Actually, no...!?
This might be the answer to my problem. Let me describe the problem further.
Call my main-thread "A". "A" starts a new thread, "B", witch will do some work. At the end of "B" a small label will be printed using the System.Drawing.Printing.PrintDocument.Print() method. As I have got it, this standard method starts a new thread "C", a printing-thread.
I do not wait for "C" to terminated in "B", parhaps I should...
Thanks for your reply.
//Daniel
|
|
|
|
|
Hi,
Try using the Thread.Join() member which causes the calling thread to block until the thread terminates.
I do not know how your workflow works, but please see the example in
http://msdn2.microsoft.com/en-us/library/system.threading.thread.aspx
Regards
|
|
|
|
|
Hi all,
I am using threads to asynchronously work on independent forms in the following way:
Thread th = new Thread(new ThreadStart(batchViewer.InvokeBatch));
th.IsBackground = true;
th.Start();
batchViewer is a class in another namespace.
InvokeBatch is a method in batchViewer.
Now to come back to the class where thread is created i get the problem of circular dependency.
How do i CallBack when the thread is completed?
Thanks.
|
|
|
|
|
Hi,
that depends on your situation. One way would be to add an event to batchViewer which is fired when the InvokeBatch call is completed. You could than handle this event. Be aware of the fact that the event handler will be called within the context of the thread. So you'll have to use Invoke if you want to pass the call into your GUI thread.
Robert
|
|
|
|
|
Why not just use a delegate as a property of the batchViewer? Set it before starting the thread, and call back to it when InvokeBatch is finished?
--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
|
|
|
|
|
Not sure how it fits BUT I for one thank you for sharing your knowledge..
Without it I be lost at what to do for ANYTHING!
|
|
|
|
|