|
how exactly would i do that? everything i try gives me exceptions.
thanks in advance,
sam kline
|
|
|
|
|
What did you try ?
string s = "client #1 - 255.255.255.255:8000";
Match match = Regex.Match(s, @"client #(\d*)", RegexOptions.IgnoreCase);
MessageBox.Show(match.Groups[1].Value);
This shows '1' in a message box.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
thanks a lot! it worked.
try
{
Match match = Regex.Match(connectedusers.SelectedItem.ToString(), @"client #(\d*)", RegexOptions.IgnoreCase);
return Convert.ToInt32(match.Groups[1].Value);
}
catch (FormatException)
{
return 0;
}
catch (NullReferenceException)
{
return 0;
}
|
|
|
|
|
I want to use GDI to draw some images in a "fullscreen" mode. What is the best way to do this? When I seem to hide pieces of my form turn it black and make it the resolution of the monitor there seems to be a "pause" when covering up the start menu. This makes me think I'm not approaching it the right way. Anyone know the proper way to do this?
|
|
|
|
|
Just resize your window so that the non client areas are outside the bounds of the screen.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I order to switch to a "fullscreen" mode you must set the Window class's
dwExStyle=WS_EX_APPWINDOW;
dwStyle=WS_POPUP;
And force the window to fill the entire screen.
I think the changes to the window class I mentioned above can be achived if you set the border property of a window to none. And, if you have problems with the TaskBar, set the TopMost property to true
I hope you understand...because is a rough world out there...
|
|
|
|
|
How would you program a generic collection class to allow only classes inherited from, say Person, class. Here is the code article by Mahesh Kumar on this subject. He codes this for any type, but suppose in his sample, employee and customer are of a particular type, say, "Worker" how would this code be changed.
smh1
|
|
|
|
|
Not used VS 2005 yet but from a little bit of reading around the subject I'd guess that you would use generic constraints for this type of problem.
Not sure of the syntax from memory but something like
Collection<Employee> where Employee : Worker
i.e., Employee has to inherit from Worker or implement an interface called Worker (IWorker for .NET of course).
Kevin
|
|
|
|
|
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
|
|
|
|