|
In VS2005, you'd do this
ArrayList<Worker> list = new ArrayList<Worker>;
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
There is no generic ArrayList in VS2005.The generic equivelant of the Arraylist is List<T>.So you could write
List<Worker> list = new List<Worker>();
-- modified at 18:31 Tuesday 22nd November, 2005
|
|
|
|
|
*blush* I did notice that, actually. But I forgot.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I think I did not formulate this properly (partly because I don't understand it fully). Question is; what is the syntax in C# for using multiple contraints on a generic collection class that uses the collectionbase.
The sample that I show in my text is from an article that appeared here where Mahesh uses the CollectionBase for a generic collectionclass but does not use multiple contraints. So that is my problem.
If I don't use CollectionBase I have to use an array, I guess, which I didn't want to use because the Collectionbase code for insert and remove is so nice.
Thanks
smh1
|
|
|
|
|
Hi, I have a problem validating with a XmlValidatingReader and a .xsd file
the validation breaks when the importDate attribute is parsed
< Info importDate = "1967-08-13" />
in the .xsd is defined as
< xs:attribute name="importDate" type="xs:date" use="required" />
and the error message is
"The 'importDate' attribute has an invalid value accordint to its data type. An error occurred at, (12, 44)"
Anyone has an idea why this happens, when I validate the same XML file in the XMLSpy it works fine, then i run my program and it breaks in that line, if I remove the line then everything works
Thanks in Advance
Isaac B
|
|
|
|
|
hi,
im having trouble trying to dynamically create and add a textboxes to cells in a datagrid im just wondeing if this is possible and if so does anyone have any idea of how exactly to go about doin it.Thanks in advance
Tim
|
|
|
|
|
A DataGrid displays data and let's you modify it into a special control derived from the DataGridColumnStyle . The TextBox-looklike contol that is avaliable on a DataGrid actualy is a DataGridTextBoxColumn .
When you set a DataGrid's Data Source if a Custom TalbeStyle is not provided, then a standard one is created. So basicly you don't have acces to the "TextBoxes into the cells".
But if you do not supply a Custom TableStyle and make changes to the DataSource (table) you may see the correct results onto the Grid. (na. adding more columns to the table, or if you do have a table style - lets say you preffer the columns to be sorted - be sure to update the table style afther adding a new column)
I hope you understand...because is a rough world out there...
|
|
|
|
|
I have application, that creates 2 threads, Both threads use the same resources and I want, they to be synchronised using Mutex.
I am using code like this
public class Test
{
protected Mutex mutex;
public Test()
{
mutex = new Mutex(false);
Thread A = new Thread(new ThreadStart(TF1));
Thread B = new Thread(new ThreadStart(TF2));
A.Start();
B.Start();
}
void TF1()
{
while(true)
{
mutex.WaitOne();
Console.Write("do some work 1");
mutex.Release();
Thread.Sleep(100);
}
}
void TF2()
{
while(true)
{
mutex.WaitOne();
Console.Write("do some work 2");
mutex.Release();
Thread.Sleep(100);
}
}
}
--------------------------------------------
It works fine some time, but one moment
both Threads are waiting for something, for example
Console Input or Window Resize.
And I do not understand why.
(Of course, I am not using "Console.Read" function in a Thread functions. )
|
|
|
|
|
Try switching your Thread.Sleep(100) with your mutex.Release(). Since Thread.Sleep() is a static method you can't be sure which thread is sleeping if you have released the synchronization
Also, I don't think your implementation is correct. Since your threads do not own the Mutex I do not believe they will be synchronized. You should have both threads call the same function so the Mutex can protect the resource.
public class Test
{
protected Mutex mutex;
public Test()
{
mutex = new Mutex(false);
Thread A = new Thread(new ThreadStart(TF));
Thread B = new Thread(new ThreadStart(TF));
A.Start();
B.Start();
}
void TF()
{
while(true)
{
mutex.WaitOne();
Console.Write("do some work {0}", Thread.CurrentThread.Name);
Thread.Sleep(100);
mutex.ReleaseMutex();
}
}
}
and since your synchronization is inside an infinite while loop I don't know what will happen as far as sharing process time
-- modified at 16:11 Tuesday 22nd November, 2005
|
|
|
|
|
Thank you! I'll try to make it static now.
BIG Thanks!
|
|
|
|
|
whizzs wrote: Also, I don't think your implementation is correct. Since your threads do not own the Mutex I do not believe they will be synchronized. You should have both threads call the same function so the Mutex can protect the resource
Huh? A threads owns the mutex once the WaitOne function completes execution. And it's absolute *** that the code will work only if the mutex is within one function. The only requirement is that the Mutex object must be shared between the two threads, which the OP code does.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Alexandr Sergeevich Ilyin wrote: but one moment
both Threads are waiting for something, for example
Console Input or Window Resize.
Could you be a bit more clear? Do you notice just a pause or do the two threads deadlock?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
It is not deadlock, Just pause.
It is enough to run some application or resize window to continue...
--------------------------------------------------------------------
In .NET examples Mutex variable is always static,
is it Important ? Why ?
|
|
|
|
|
Take a look at AutoResetEvent or ManualResetEvent as an alternative to using Mutex. Also looking at your code both your threads go into indefinite wait. one solution is: in TF1 delete the mutex.WaitOne statement. Then replace delete the Thread.Sleep(100) line. As the last statement in TF1, add mutex.WaitOne(). This will execute TF1 first, who writes the message, releases the Mutex and then goes into a Wait for state until signaled by TF2. In this way your threads will take turns.
If you need both threads to operate concurrently then you need to add the mutex coordination to the mainline code that started the threads. BTW, you dont need the Thread.Sleep() in TF2 either unless you are just trying to slow down the I/O.
Mike
|
|
|
|
|
Mmmm, video
|
|
|
|
|
|
I am trying to capture the output from a function that computes some data then draw this in a text box. The following link does this for a .exe but I would like to do this for an owner-process.
http://www.codeproject.com/csharp/LaunchProcess[^]
Your help is appreciated.
Kash
|
|
|
|
|
Take a look at this[^] article. Basically, it does a Process.Start and then redirects console I/O to display it in a textbox.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi Senthil,
Thanks for that. This works fine for writing data within C# to the shellcontrol. However, I am trying to capture the I/O from a dll written in another language. I can usually capture this by using AllocConsole(). Is there a way to do this in your control?
For example: my dll subroutine is called aTest() and is declared as a void. aTest() merely outputs data to the console.
|
|
|
|
|
I try search 'tapi faq' in google but there nothing usefull for my project.Now i am using VS2003 and tapi3. If you know how to playback wave file please help.
thank
|
|
|
|
|
Hi,
I have one of those real computer-science-type questions, and seeing as I never went to uni I missed that class
I have 4 types of object which represent entities from my database, and as such each has an 'Id' property which is my unique key from the database - therefore it is a good candidate for the GetHashCode override for that object - ie/
class MyEntity
{
private int id;
public int GetHashCode()
{
return id;
}
}
Now, I have another object which is composed of my 4 Entities
class MyComposite
{
private MyFirstEntity firstEntity;
private MySecondEntity secondEntity;
private MyThirdEntity thirdEntity;
private MyFourthEntity fourthEntity;
}
each type of entity overrides GetHashCode in the manner described above.
Now my question is, I am trying to generate a unique has code for MyComposite, which does not itself have a unique database key to use - without much success. The problem is 2 fold
1) In the example above, MyFirstEntity & MySecondEntity can have an id of -1 (meaning it is not present in the database) and I think this is affecting my calculations (see below)
2) As these are all db identities from differing tables they can of course all have Id's in the range 1..N - again I think this is causing my duplicate keys problem.
What I have tried so far:
firstEntity.GetHashCode() ^ secondEntity.GetHashCode() ^ thirdEntity.GetHashCode() ^ fourthEntity.GetHashCode()
This caused obvious duplicates for differing combinations of entities very early on.
The other attempt, based on an obvious google search, appeared to work at first but after further testing with a wider range of numbers caused many duplicates.
double e1Hash = (firstEntity.GetHashCode() * Math.Pow(100,3));
double e2Hash = (secondEntity.GetHashCode() * Math.Pow(100,2));
double e3Hash = (thirdEntity.GetHashCode() * 100);
double e4Hash = fourthEntity.GetHashCode();
int hash = (int)((Math.Abs(e1Hash+e2Hash+e3Hash+e4Hash ))%int.MaxValue);
I did change the value "100" to be a high prime (41 I used) after reading another very mathmatical paper from a university... but it did not affect things that much.
I tried removing the call to Math.Abs thinking that it may spread the range over -ve and +ve numbers but alas this did not fix my problem.
Any clues very much appretiated and TIA!
|
|
|
|
|
If you are planning to use the hash code generated by the classes you described with the .Net HashCode class, than you will be happy to know that string keys are alowed (you could concatenate each id convered to a string with a dot between values)
If not the simplest solution comes by creating "concatenating each key with addition". Meaning, for example if your maximum reached value for the id has 4 digits, and you have 3 values different from -1 (lets say 100, 120 an 30) your unique id can be a linear arrangement of the values : 0000 0100 0120 0030 = 10001200030 (it is usefull to use 0000 for -1 if your id can not be 0, although -1 has it's own binary representation)
In order to implement such an uid you should be aware of the max numer of digits and byte[] operations.
Good luk.
I hope you understand...because is a rough world out there...
|
|
|
|
|
Thanks for your response!
Vlad Stanciu wrote: the .Net HashCode class
I assume you mean Hashtable - in which case yes it is to be used with that.
Now, I had thought of concatenating the 4 values into a string and calling GetHashCode() on that string, but i thought this was a bit of a kludge... I guess i was getting too snmart for my boots
I now think its a better solution, but if any math-heads out there know the real solution id be interested to hear.
|
|
|
|
|
You are right about the first part, the class is Hashtable (many people do mistakes when they are tired).
Glad to be able to help you.
I hope you understand...because is a rough world out there...
|
|
|
|
|
J4amieC wrote: Now, I had thought of concatenating the 4 values into a string and calling GetHashCode() on that string, but i thought this was a bit of a kludge... I guess i was getting too snmart for my boots
Are string hash codes guaranteed to be unique? I don't know the answer to that, but I'm guessing no.
Just wanted to point out that the solution Vlad described was not to concatenate strings but to bit-shift and OR together your ids. This guarentees uniqueness, but whether or not it's doable depends on the range of your ids.
J4amieC wrote: I now think its a better solution, but if any math-heads out there know the real solution id be interested to hear.
Creating good hash codes seems to be an art in and of itself, kind of like creating good psuedo random number generators. I don't know much about this field, but I believe a good hash code algorithm will generally give values that are evenly distributed. They don't necessarily have to be unique.
This is why if you override GetHashCode , it's recommended (required?) that you override Equals as well. That's so if a duplicate hash code is encountered, Equals can be used to find the actual item. Though, I can understand wanting to avoid duplicates for performance reasons.
At any rate, you may know all of this, just chiming in with my two cents.
[EDIT]
Actually, after rereading Vlad's post, it looks like what he describes in the first paragraph does use string concatenation to create unique keys. An interesting approach.
In the second paragraph, I'm assuming he's talking about bitwise operations instead of string concatenation. At any rate, both approaches look ok to me.
[/EDIT]
-- modified at 16:03 Tuesday 22nd November, 2005
|
|
|
|