|
Thanks for the answer Luc,
I see... so there is no way to do that?
That's a problem.
Do you know a good article involving interthread communication?
I'll try looking for something here in codeproject now, but what I mean is if you know a specific good one for beginners or in any other way.
I'll learn how to use that someway.
Thanks again
Oscar
|
|
|
|
|
Hi Oscar,
No, I don't recall any exsceptional article on the subject, but that doesn't mean there are
none, it just says that's the kind of things I stopped reading long ago.
interthread communication isn't that hard. Basically the threads all can access your data,
so the one problem to avoid is having thread1 read some data while thread2 is modifying
that data, resulting in thread1 possibly having an inconsistent view of the data (parts
already changed, parts not yet updated).
The way to avoid this is typically is by locking the data whenever a consistent state is
needed and/or an "atomic update" has to be performed.
In C# the lock keyword is the key.
BTW: if you forget to apply locks, your program will typically run fine for a while,
then occasionally it will produce unexpected results.
|
|
|
|
|
Oh, I forgot to tell something...
I don't think this is normal... but when my program is drawing everything, not only the program freezes, but windows too. And that's what I'm most worried about...
Do you know what kind of problems do this?
Thanks again
Oscar
|
|
|
|
|
Hi Oscar,
if your app is not involved in system stuff, then abusing threads for graphics stuff
may and will freeze the app, but not the system.
if your app is doing special things (say interprocess communication, networking, whatever)
and your way of drawing/painting is incorrect, resulting in a temporary or permanent app
freeze, then your handling of the special things, evn when implemented correctly, is likely
to suffer too, possibly leading to less than optimal system behavior.
|
|
|
|
|
I see... I'll look for the problem then.
Okey, so I'll learn about interthread communication then.
Thanks a lot for your patience and atention Luc!
|
|
|
|
|
Hey guys
i just finished writing a class, all it is is a few 100 variables and their corresponding properties (only get accessors)
all the variables values are set in the constructor of the class and comes from a single sql query.
is there any way i can foreach through all the properties ive created for the class?
the idea is to do MessageBox.Show(PropertyName.ToString() + " --> " + PropertyValue.ToString()) so i can manually check that the right things are going into the right variables & gets accessed with the right properties
thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
Off the top of my head: You could use reflection to get the PropertyInfo for each of these from the Type , then iterate over the PropertyInfo[] array calling Invoke on the getter.
|
|
|
|
|
Reflection is your friend.
foreach (PropertyInfo propertyInfo in this.GetType().GetProperties())
{
Console.WriteLine(propertyInfo.Name + "=" + propertyInfo.GetValue(this, null));
}
You can use the other overload for GetProperties to get non-public and non-static properties as well.
That said, I'd be worried if I had hundreds of properties in a class.
|
|
|
|
|
thanx, ill try it quickly
S. Senthil Kumar wrote: I'd be worried if I had hundreds of properties in a class.
i know it sounds weird, the class contains all the parameters for a shift(im developing a time & attendance package) and there really are 100's of variables that make up a "shift" because certain roundings must happen in certain intervals before a shift starts and ends and the same for coming late and leaving early.... its quite a complicated industry
anywho... thanx for the help
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
I would venture to suggest that if there are that many parameters, you could turn the properties into a ShiftParameter and stuff them into a collection, and add what's needed. With the custom class, you can add validation parameter by parameter, and I think it would be easier to maintain and extend.
Scott P
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
If it is possible than it will be only through Reflection bcz you want to get class information at the runtime
|
|
|
|
|
|
Define an enumerator and use the yield return statement.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
Hi,
I am really struggling to work with the parameters in Crystal Reports in Visual Studio 2008 C#.
I keep on getting the annoying parameter input dialog which i dont want.
Can anyone suggest a good book for Crystal Reports XI for Visual Studio 2005 or 2008?
Also i work with SQL 2005.
The books i have found online do not have any good reviews and user comments :/
Thanks
|
|
|
|
|
I have made a UserControl for designing WYSIWYG tables for printing.
The user control has a DataGridView control which is visible through the myUserControl.Grid property
Passing the new DataGridControl works fine (myUserControl.grid = newDataGrid; ), except that the UserConrol's DataGridView is not visually updated/refreshed.
My question is, how can I pass a DataGridView to the UserControl and make it repaint/refresh/update to show the new instance of the DataGridView control?
I'm not using any data binding, and I have tried all the .Update() and Refresh() mehods available (I think).
Thanks,
Marius
|
|
|
|
|
Hi. I need to do this:
AnotherClass.Cmd() //does a Process.Start() which takes 30 secs to complete
while(AnotherClass.Cmd().Thread.IsAlive) { this.label.text=i.tostring(); i++}
DoThat()
I tried many things with normal threads and asnyc calls but I couldn't manage to do it without locking the main thread(so label/form is not refreshed) or go to DoThat() without completing Cmd()
Any ideas are appreciated
|
|
|
|
|
What problem are you experiencing? It's hard to tell... Exceptions? Not updating? Need more info.
Scott P
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Are you trying to prevent the UI from blocking until AnotherClass.Cmd() completes? If that's the case, you can use http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx[^] to push the time consuming call to another thread. Something like
BackgroundWorker bgWorker = new BackgroundWorker();
bgWorker.DoWork += new DoWorkEventHandler(
delegate(object sender, DoWorkEventArgs e) { AnotherClass.Cmd(); });
bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
delegate(object sender, RunWorkerCompletedEventArgs e) { DoThat(); });
bgWorker.RunWorkerAsync();
Does that help?
|
|
|
|
|
S. Senthil Kumar wrote: Are you trying to prevent the UI from blocking until AnotherClass.Cmd() completes?
Yes and no. I need to display some values(constanly changed) using label and while Cmd() runs and when it's completed resume the normal workflow. I'll check BackgroundWorker, thanks.
|
|
|
|
|
Sorry if I am asking DB question in the wrong message board
hi friends
I tried to run the script db.sql using SQLCMD.I tried to execute it with the following command....SQLCMD -E -i C:\a\db.sql.
It is not working in my system.It is showing the error "Could not open connection to SQLSERVER [2]"..."login timeout expired"....But this command is working fine in other system.Would you help me to trouble shoot this problem
With regards
Denver
Reply·Em
|
|
|
|
|
Hi,
I am loading a dll say XYZ.dll dynamically from console application by using activator.createinstance() method. This XYZ.dll is having reference to a data access layer ABC.dll which has reference to the 3 MS-DAAB dlls of enterprise library:
1. Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings
2. Microsoft.Practices.EnterpriseLibrary.Data
3. Microsoft.Practices.ObjectBuilder
I have placed these 3 dlls and ABC.dll in the folder with the exe of console application. However XYZ.dll is not placed there as it will be loaded at runtime specifying a certain path. Now when I try using code which uses the MS DAAB dlls then I am getting an error:
Unable to cast object of type 'Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings' to type 'Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings'
(I do not get this error when I am not dynalically loading the dll)
Note: I have specified the dataConfiguration section in App.config of Console Application.
Any help is appreciated.
Pankaj Chamria,
Software Programmer.
|
|
|
|
|
I am trying to add a AD user to a local group, but keep on getting an exception:
ex Message - Exception has been thrown by the target of an invocation.
ex InnerException - An invalid directory pathname was passed
<br />
DirectoryEntry activeDirectory = new DirectoryEntry("LDAP://DomainName.com", LoggedOnUser, LoggedOnPassword);<br />
DirectorySearcher dsUsers = new DirectorySearcher(activeDirectory);<br />
<br />
dsUsers.Filter = "samaccountname=" + userName;<br />
<br />
SearchResult srCheckUser;<br />
if ((srCheckUser = dsUsers.FindOne()) != null)<br />
{<br />
DirectoryEntry newUser = srCheckUser.GetDirectoryEntry();<br />
currentGroup.Invoke("Add", new object[] { newUser.Path.ToString() });<br />
}<br />
<code>
|
|
|
|
|
|
Hello..
I want to use the DataGridView only as View, that's why, I don't want to allow user to select any cell.
If user select a cell, it will be marked as "dark blue cell". How to avoid this ?
Are there any properties to disable any selection from user ?
Thx...
|
|
|
|
|
you can set the DefaultCellStyle of a DataGridView, this will allow you to give the appearance of the Cell NOT being selected. like this ...
<br />
DataGridViewCellStyle style = new DataGridViewCellStyle();<br />
style.SelectionBackColor = Color.White;<br />
style.SelectionForeColor = Color.Black;<br />
dataGridView1.DefaultCellStyle = style;<br />
BUT, the easiest would be to use the CellStateChanged event, like this ...
<br />
private void dataGridView1_CellStateChanged(object sender, DataGridViewCellStateChangedEventArgs e)<br />
{<br />
if (e.Cell.Selected)<br />
{<br />
e.Cell.Selected = false;<br />
}<br />
}<br />
<br />
hope it helps
<font color="blue">Csharp</font> me = (<font color="blue">Csharp</font>)Dynamic_Sysop; <font color="#008000">// My Signature.</font><br><font color="#008000">$twins</font> = <font color="#008000">me.twins</font>(<font color="#800080">"Taylor"</font> , <font color="#800080">"Delta"</font>); <font color="#C0C0C0">// My twin daughters.</font><br>echo <font color="#008000">$twins</font>;</br></br>
|
|
|
|