|
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
|
|
|
|
|
hi to all,
how can i change the application major, minor and revision with the designer in c# win form.
best regrads and thanks in advance
fady
|
|
|
|
|
Open AssemblyInfo.cs and look for a string similar to this '[assembly: AssemblyVersion("1.0.0.02")]' by default I think the last number is an * and auto incremented.
|
|
|
|
|
Its in the AssemblyInfo.cs file with your project - winform, class library, web app et al.
|
|
|
|
|
Hello,
I've got a very big problem with the .NET remoting. I've developed a synchronization library using .NET 2.0 that uses classes derived from MarshalByRefObject . These classes have public events which remote objects can subscribe to. Under the 2.0 framework, everything works like a charm.
Now I have to port the library to .NET 1.x since my teachers want to be able to test and compile the code by themselves. I though that this would be a task of a few minutes. I guessed wrong. The runtime refuses to serialize the delegates. I've read something about RemotingSurrogateSelector , but I can't find a thorough explanation about how the class should be used to handle this type of serialization.
Does anybody know how I can subscribe to a remote event?
Source example:
public delegate void MyDelegate();
class RemoteObject : System.MarshalByRefObject
{
public event MyDelegate EvMyEvent;
}
class MyClient
{
private void MyDelegateFunction()
{
}
public MyClient()
{
RemoteObject oRO = null;
oRO.EvMyEvent += new MyDelegate(MyDelegateFunction);
}
}
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
I don't know why this happens either, but making the delegate function (MyDelegateFunction ) public solves the problem. Ugly, I know, but it works. I guess this is a bug and has been corrected in .NET 2.0
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi,
Thanks for the reply. It's ugly indeed. It's that I'm not a strict OO purist... I hope that everybody moves to the .NET 2.0 framework soon..
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|