|
You were lucky
|
|
|
|
|
Brian Gideon wrote:
You were lucky
I can post the source code for you and you will see you are more lucky than me after running it and having no exception! ;P (need for your mail)
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
TimK wrote:
What do you think?
You are correct.
|
|
|
|
|
I mentioned this problem briefly in my original post. My example code assumes that all event handlers have been added prior to calling ThreadTest.Start(). It's easy is see that unsubscribing with -= will cause a lot of problems after the threads have been started, but += could be problematic as well. This problem is difficult solve correctly and that is why I suggested to intentionally leave the ThreadTest class unsafe for multithreading.
Simply locking the code that raises the event is insufficient. You must lock the -= and += operators as well. This can be done with special syntax, using the add and remove keywords.
public class ThreadTest
{
private ArrayList _events = new ArrayList();
public event EventHandler MyEvent
{
add { lock (this) { _events.Add(value); } }
remove { lock (this) { _events.Remove(value); } }
}
public void Start()
{
}
private void ThreadMethod()
{
while (true)
{
ArrayList clone;
lock (this)
{
clone = (ArrayList)_events.Clone();
}
foreach (EventHandler e in clone)
{
e.DynamicInvoke(...);
}
}
}
}
If you're going to do this you might as well make every method on ThreadTest thread-safe to avoid confusion and inconsistency. This solution still requires that subscribers handle their on synchronization.
Brian
|
|
|
|
|
I have a DataGrid bound to source. The source table has a column that contains status numbers (integers), and the dataGrid shows these numbers. I have another table in the database which associates these numbers with a string.
Does anyone know of a way I can make the dataGrid show the associated string (from the other table) instead of the numbers in the current table?
-- James --
|
|
|
|
|
Add next table to the DataSet with Your dictionary and create relation into it. See Expression property of DataColumn. It can do this association.
Hi,
AW
|
|
|
|
|
Why don't you make a "Select" Query with a join and create a DataTable in memory to display it on the grid ?
HTH
Braulio
|
|
|
|
|
Thanks AW and Braulio for the ideas. I'll explore these.
-- James --
|
|
|
|
|
I'm looking to sort a ListView in detailed view with ascending/descending. Something like Explorer where the arrows are shown, as well.
I've got a class that someone else in there now, but it only sorts ascending and it's not "intelligent" with numbers; it sorts 1 10 11 12 ... 2 20 etc.
Apparently this isn't built in to the ListView object itself, so does anyone have a nice custom class that does this?
|
|
|
|
|
There's a ListViewSorter implementation in the Genghis Project[^] that includes chevrons, though I have found the chevron implementation to be quite buggy.
You might also like to check out the ListViewFilter[^] article here on CP.
|
|
|
|
|
though I have found the chevron implementation to be quite buggy.
Wow, you weren't kidding. I got an exception after every other sort. It did exactly what I wanted though; hope they look into making it a bit more stable.
|
|
|
|
|
I was wondering if there is any (preferably relatively straighforward) way for a method in C# to obtain the object which made the call. For example...
namespace Example
{
public class A
{
private B b;
public A()
{
b = new B();
b.Call();
}
}
public class B
{
public B()
{
}
public void Call()
{
object caller = null;
}
}
}
I hope this makes some sense. Any hints / tips are much appreciated.
--
The Last Bastion
|
|
|
|
|
|
Have a look at the stack trace objects in the debugging namespace, cant remember offhand where it is (not on a .NET Pc at the moment!) System.Diagnostics might be the one. Not 100% sure if it returns the object, or just a list of methods called.
Cheers, James
James Simpson
Web Developer
imebgo@hotmail.com
|
|
|
|
|
|
leppie wrote:
hey where is the object?
There isn't one, also what would you do if the caller was a static method? In that case there is no object reference that is doing the calling.
AFAIK, the best you can hope for is to get the class/struct name and possibly get the Type object representing it.
James
At Jethro Tull's August 28, 2003 concert Ian Anderson mentioned that the group would be performing a medley of title tracks. The songs were "Songs from the Wood", "Too Old to Rock and Roll; Too Young to Die"; and from the Heavy Horses album, "Stairway to Heaven".
|
|
|
|
|
My article on custom trace listeners has a decent write-up on this:
TraceListeners and Reflection
Towards the end there's a section on "StackFrame and StackTrace", with some example code.
Jerry Dennany
|
|
|
|
|
Hi,
I am having a lot of problems of calling an unmanaged DLL.
The parameters it is expecting are two structures, (one for input and the other is output). When I run it, the output structure is not being populated.
I have been using the marshalAs for the datatypes,
[MarshalAs(UnmanagedType.LPStr, SizeConst=1)]
public string Name;
Does anyone know of good examples where they are passing classes or structures. Also I think the API needs a fixed structure. Does the sizeConst in the attribute handle this?
|
|
|
|
|
Hi Everyone,
I'm on a mission to learn and successfully utilize the most popular of the software design patterns out there today.
I don't come from an OO background but after using .net for a couple of years I'm rougly getting into shape and I now really need to solidify my knowledge of design patterns.
I've found some explanations on the web and even bought a book called "C# Design Patterns" by James W. Cooper but found the examples poorly explained, written, and drawn out. This book is awful and has not helped me so far. MSDN examples have been overly simplified and really do not provide any useful code samples that would apply to everyday development. Through the course of many of my projects I have found that many times I was using some of the patterns in one way or another unwittingly, in other words; they just came naturally.
Can anyone provide me with some links/books/resources on how to better familiarize myself w/ software design patterns? Are they even useful? Should I bother? I would prefer samples in C# but any good info is welcome.
Most appreciated, thanks!
****************************
Melodious Funk
|
|
|
|
|
http://www.dofactory.com/Patterns/Patterns.aspx
|
|
|
|
|
|
I'm trying to open and query an AS400/DB2 Database via OleDB. I can do this fine via ODBC, but when I try to use Ole DB, I get the following error:
OleDbException: Multiple-step OLE DB operation generated errors.
My code and query is quite simple, and the exception is caused on the OleDbConnection.Open() method. Could anyone shed some light on what this may mean?
Here's my code:
string source = ("Provider=IBMDA400;Data Source=10.10.10.1;USERID=myusername; Password=mypassword;";
OleDbConnection con = new OleDbConnection(source);
try
{
con.Open();
}
catch (Exception a)
{
MessageBox.Show(a.ToString());
return;
}
Thanks in advance.
|
|
|
|
|
Hi dear,
How can I convert the following VB Script to C# ?
Function En2Fr (sStr)<br />
<br />
Dim nLen, i, ch, sFrStr<br />
<br />
nLen = Len(sStr)<br />
<br />
if nLen = 0 OR IsNull(nLen) then<br />
En2Fr = sStr<br />
Exit Function <br />
end if<br />
<br />
sFrStr = ""<br />
<br />
for i = 1 to nLen<br />
ch = Mid(sStr, i, 1)<br />
if 48 <= Asc(ch) AND Asc(ch) <= 57 then<br />
ch = ChrW(Asc(ch) + 1728)<br />
end if<br />
sFrStr = sFrStr + ch<br />
next<br />
<br />
En2Fr = sFrStr<br />
<br />
End Function<br />
Thank you in advance.
|
|
|
|
|
Have you tried doing the conversion yourself, or are you just too lazy? If you have tried it, which part are you specifically having problems with?
Regards,
Alvaro
Hey! It compiles! Ship it.
|
|
|
|
|
I have a problem to get the ascii characters in fact i have a problem with converting these lines
<br />
if 48 <= Asc(ch) AND Asc(ch) <= 57 then<br />
ch = ChrW(Asc(ch) + 1728)<br />
|
|
|
|