|
Hi Arejay,
I am not a db specialist at all, but this may help:
your code starts a number of threads each executing the "CalculateWorker" method.
BTW: methods dont get instantiated, they just get executed, using the local context
(e.g. the stack belonging to the executing thread).
So the app has several threads executing the same code, if that code refers
to global data (all your class members) you may get concurrency problems.
If for instance you create and use some object (maybe a table adapter) and
suddenly that object gets manipulated by multiple threads, anything can happen.
Rather than using such shared data (and trying to add all necessary locks), I
would advise to give each thread its own data, i.e. instantiate a "job" object
for each thread you create (better yet, create the thread inside the job object).
Hope this helps.
|
|
|
|
|
Thank you!
So... I've created a worker class and I'm creating multiple instances of the worker. Within the worker class I create an asyn thread using the BeginInvoke. Now I need update the calling form.
public delegate void CalculationCompletedEventHandler( object sender, CalculationCompletedEventArgs e );<br />
In the Worker class:
<br />
public class Worker : Component {<br />
public event CalculationCompletedEventHandler CalculationCompleted;<br />
<br />
private void doCalculationCompleted( object operationState ){<br />
CalculationCompletedEventArgs e = operationState as CalculationCompletedEventArgs;<br />
OnCalculationCompleted( e );<br />
}<br />
<br />
protected void OnCalculationCompleted( CalculationCompletedEventArgs e ){<br />
if ( CalculationCompleted != null ) {<br />
CalculationCompleted( this, e );<br />
}<br />
}
On the form:
internal void OnUpdateProgress( object sender, CalculationCompletedEventArgs e ){<br />
if ( this.InvokeRequired ){<br />
this.Invoke( doProgressUpdate, new object[] { sender, e } );<br />
}else{<br />
lock ( this ){<br />
} <br />
}<br />
}<br />
<br />
Worker w = new Worker(id);<br />
w.CalculationCompleted += OnUpdateProgress;
In the above is the doCalculationCompleted method needed in the Worker Class?
I'll update my code and let you know how it went.
Thanks again.
I'm listening but I only speak GEEK.
|
|
|
|
|
Hi Arejay,
you can do with and without a completion event.
WITH: the callee provides such an event, caller attaches something to it.
WITHOUT: the caller implements some interface (say IDone, with a Done() method),
and the callee's constructor accepts an object argument that implements that
interface; when done the callee just executes the IDone, hence executing
the caller's Done() code.
The advantage of events (being able to attach multiple delegates) typically
is of no value in the given situation...
PS: two remarks about your OnUpdateProgress method:
- it invokes doProgressUpdate, the normal pattern is to invoke itself
- the lock may not be needed, since the else part executes on the UI thread,
hence needs not to be re-entrant. (If other pieces of code contain the same
lock and execute on another thread, net result is such thread may keep
the UI thread from running, which may harm the responsiveness)
Regards.
|
|
|
|
|
I've post a newer version of the application with the connection strings cleaned up and the database has been srunk down. Are Jay's Profile Page[^]
I'm listening but I only speak GEEK.
|
|
|
|
|
Hi,
I have an wierd exception raised in my code when I query the 2003 Acitve Directory for the User information.
I am getting an Exception in the line
'ResultPropertyCollection props = srResult.Properties'
which says 'Object Refernece not set to an instance of an object'
but the same code works fine with a test page what i created...and even the same code works fine with windows 2000 server which is now in Production.
I would really appreciate some kind of help with this..
// constructor
public UserInfo(UserDirectory parentDirectory, String userAttribute, UserSearchType searchType)
{
if (parentDirectory != null)
{
DateTime LDAPStarted = DateTime.Now;
try
{
Directory = parentDirectory;
String filter = "(SAMAccountName=" + userAttribute + ")";
if (searchType == UserSearchType.Email)
filter = "(mail=" + userAttribute + ")";
if (searchType == UserSearchType.LegacyExchangeDN)
filter = "(legacyExchangeDN=" + userAttribute + ")";
if (searchType == UserSearchType.DistinguishedName)
filter = "(distinguishedName=" + userAttribute + ")";
logger.LogDebug(String.Format("UserInfo ({0},{1},{2}). filter={3}", parentDirectory, userAttribute, searchType, filter));
logger.LogDebug(String.Format("LDAP - Server:{0}, Domain:{1}, UserName:{2}", Directory.Configuration.LDAPServer, Directory.Configuration.LDAPDomain, Directory.Configuration.LDAPUsername));
DirectoryEntry deRootDSE;
DirectoryEntry deDomain;
DirectorySearcher dsSearcher;
SearchResult srResult;
deRootDSE = new DirectoryEntry("LDAP://" + Directory.Configuration.LDAPServer + "/RootDSE",
Directory.Configuration.LDAPDomain + "\\" +
Directory.Configuration.LDAPUsername,
Directory.Configuration.LDAPPassword,
AuthenticationTypes.ServerBind);
deDomain = new DirectoryEntry("LDAP://" + Directory.Configuration.LDAPServer + "/" +
deRootDSE.Properties["defaultNamingContext"].Value.ToString(),
Directory.Configuration.LDAPDomain + "\\" +
Directory.Configuration.LDAPUsername,
Directory.Configuration.LDAPPassword,
AuthenticationTypes.ServerBind);
dsSearcher = new DirectorySearcher();
dsSearcher.SearchRoot = deDomain;
dsSearcher.Filter = filter;
dsSearcher.SearchScope = SearchScope.Subtree;
dsSearcher.PropertiesToLoad.Add("cn");
dsSearcher.PropertiesToLoad.Add("sn");
dsSearcher.PropertiesToLoad.Add("canonicalName");
dsSearcher.PropertiesToLoad.Add("displayName");
dsSearcher.PropertiesToLoad.Add("distinguishedName");
dsSearcher.PropertiesToLoad.Add("givenName");
dsSearcher.PropertiesToLoad.Add("name");
dsSearcher.PropertiesToLoad.Add("homeMDB");
dsSearcher.PropertiesToLoad.Add("homeMTA");
dsSearcher.PropertiesToLoad.Add("mail");
dsSearcher.PropertiesToLoad.Add("mailNickname");
dsSearcher.PropertiesToLoad.Add("proxyAddresses");
dsSearcher.PropertiesToLoad.Add("sAMAccountName");
dsSearcher.PropertiesToLoad.Add("userPrincipalName");
dsSearcher.PropertiesToLoad.Add("legacyExchangeDN");
dsSearcher.PropertiesToLoad.Add("objectclass");
dsSearcher.PropertiesToLoad.Add("member");
srResult = dsSearcher.FindOne();
ResultPropertyCollection props = srResult.Properties;
HomeMDB = GetDefaultPropValue(props, "homeMDB", "localhost");
DirectoryEntry deHomeMDB = new DirectoryEntry("LDAP://" + HomeMDB);
SAMAccountName = GetDefaultPropValue(props, "sAMAccountName", PROP_NA);
CN = GetDefaultPropValue(props, "cn", PROP_NA);
SN = GetDefaultPropValue(props, "sn", PROP_NA);
CanonicalName = GetDefaultPropValue(props, "canonicalName", PROP_NA);
DisplayName = GetDefaultPropValue(props, "displayName", PROP_NA);
DistinguishedName = GetDefaultPropValue(props, "distinguishedName", PROP_NA);
GivenName = GetDefaultPropValue(props, "givenName", PROP_NA);
Name = GetDefaultPropValue(props, "name", PROP_NA);
HomeMTA = GetDefaultPropValue(props, "homeMTA", PROP_NA);
Mail = GetDefaultPropValue(props, "mail", PROP_NA);
MailAlias = Mail.Substring(0, Mail.IndexOf("@"));
MailNickname = GetDefaultPropValue(props, "mailNickname", PROP_NA);
ProxyAddresses = GetDefaultPropValue(props, "proxyAddresses", PROP_NA);
UserPrincipalName = GetDefaultPropValue(props, "userPrincipalName", PROP_NA);
LegacyExchangeDN = GetDefaultPropValue(props, "legacyExchangeDN", PROP_NA);
objectClasses = GetPropValues(props, "objectclass");
memberDistinguishedNames = GetPropValues(props, "member");
StoreURL = Directory.Configuration.StoreURI;
StoreURL = StoreURL.Replace("%EXCHANGE_SERVER%", OwningServer);
StoreURL = StoreURL.Replace("%MAILALIAS%", MailAlias);
StoreURL = StoreURL.Replace("%USERNAME%", SAMAccountName);
if (Directory.Configuration.StoreCredentialType.Equals(ConfigInfo.CredentialTypes.Personal))
{
//derive the domain
char[] commadelim = { ',' };
string[] splitPath = DistinguishedName.Split(commadelim);
string domain = null;
foreach (string path in splitPath)
{
char[] eqdelim = { '=' };
string[] splitvalue = path.Split(eqdelim);
if (splitvalue.Length > 1 && splitvalue[0] != null && splitvalue[0].Equals("DC") && splitvalue[1] != null)
{
if (domain != null)
domain += ".";
domain += splitvalue[1];
}
}
authDomain = domain;
DomainPasswordPair dpp = Directory.Credentials.Recall(SAMAccountName);
authUser = SAMAccountName;
authPassword = dpp.Password;
Directory.Credentials.Cache(SAMAccountName, authDomain, authPassword);
}
else
{ // Store Credential Type is Universal - use the common user and password
authDomain = Directory.Configuration.StoreDomain;
authUser = Directory.Configuration.StoreUsername;
authPassword = Directory.Configuration.StorePassword;
}
Statistics.Add(6, Directory.Configuration.ConfigName, LDAPStarted, (DateTime.Now.Ticks - LDAPStarted.Ticks) / 10000, 1, true, "SUCCESS", null);
}
catch (System.Runtime.InteropServices.COMException ce)
{
throw new Exception("FATAL: COM Exception while trying to retrieve User Info from LDAP: {" + ce.Message + "}");
}
}
else
throw new Exception("FATAL: UserInfo requires a valid User Directory instance.");
} // public UserInfo(UserDirectory parentDirectory, String userName, UserSearchType searchType)
Thanks
Zach1983
|
|
|
|
|
Hi,
sounds like dsSearcher.FindOne() is returning null. Does its documentation tell
you anything in that direction ?
I suggest you assert srResult!=null to confirm this.
|
|
|
|
|
Hi,
Thanks for the reply. As u suggested I checked dsSearcher.FindOne() and it is returning a NULL. The trace doesnt sugest me anything other than this
Error: Object reference not set to an instance of an object.. Trace: at UBS.BLISS.UserInfo..ctor(UserDirectory parentDirectory, String userAttribute, UserSearchType searchType) in d:\BLISS\App_Code\UserInfo.cs:line 152
at UBS.BLISS.UserDirectory.GetByLegacyExchangeDN(String legacyExchangeDN) in d:\BLISS\App_Code\UserDirectory.cs:line 101
at UBS.BLISS.MessageReader.GetCapturedMessageItem(IMessage iMsg, MailRetentionType retentionType, MessageType messageType, Boolean hideContent) in d:\BLISS\App_Code\MessageReader.cs:line 395. InnerException: . Source: App_Code.714yokif
I have the same code to do the search based on the LegacyExchangeDN in my test page it works fine but when i do it as a part of the application it throws this exception.
The code also works fine in Production with windows server 2000.
I kinda of struck in this, Please help me
Thanks
Zach1983
|
|
|
|
|
Hi,
since you now realize the FindOne() method may return null, you must include
code to deal with that possibility, how unlikely it may seem (otherwise
it will bomb at an inappropriate point in time)
I dont know enough about Active Directory to pinpoint your problem right away.
Here are some ideas:
- AD not present or not enabled
- some parameter value (maybe the default value of some property) not appropriate
- security problem
Good luck.
|
|
|
|
|
Hi,
I am kinda of struck in this and I found that when I hardcode the legacyExchangeDN string its getting the entry from the Active Directory but when i Parse the string from th email address
say for example Doe, John <ex: o="First" organization="" ou="First" administrative
group="" cn="Recipients/cn=jdoe">.. i parsed the string using this
--------
int startIndex = -1;
int endIndex = -1;
startIndex = inString.IndexOf("<ex:", recindex)="" +="" 4;
="" if="" (startindex=""> recIndex + 4)
endIndex = inString.IndexOf(">", startIndex);
if (endIndex != -1)
lemail = inString.Substring(startIndex, endIndex - startIndex);
-------------
It returning NULL...I dont understand why its not working, what i am doing for Hardcoding is also just outputting the lemail and Coping the same to hard code it...
Any help would be Appreciated... I am struck for more than a week....
Thanks,
Zach1983
|
|
|
|
|
sorry for the junk code
Hi,
I am kinda of struck in this and I found that when I hardcode the legacyExchangeDN string its getting the entry from the Active Directory but when i Parse the string from th email address
say for example Doe, John <EX:/o=First Organization/ou=First Administrative
Group/cn=Recipients/cn=jdoe<...... i parsed the string using this
the code is
--------------
int startIndex = -1;
int endIndex = -1;
startIndex = inString.IndexOf("<EX:", recIndex) + 4;
if (startIndex > recIndex + 4)
endIndex = inString.IndexOf(">", startIndex);
if (endIndex != -1)
lemail = inString.Substring(startIndex, endIndex - startIndex);
int email = lemail.Length;
logger.LogDebug("email " + email);
-------------------
It returning NULL...I dont understand why its not working, what i am doing for Hardcoding is also just outputting the lemail and Coping the same to hard code it...
Any help would be Appreciated... I am struck for more than a week....
Thanks
Zach1983
|
|
|
|
|
Hi,
so you have 10 lines of code that go wrong ?
how about debugging it, this means:
- either you single step through it and look at intermediate results
- or you add output ("log") statements to see intermediate results.
Whatever method you choose, you should soon figure out you made a simple
mistake (that could have been avoided by applying a more defensive
programming style).
Good hunting !
|
|
|
|
|
Hi,
I am suppose to read XML files and extract some data from certain nodes based on its attribute. What I have done is to use XmlTextReader and loop through, using select case and hardcode (inefficient and poor practice) the nodes to be extracted. I have used XmlTextReader instead of XmlDocument initially as I would not be needing Xpath. Now, I would like to know if there are ways to select the nodes based on part of its attribute name like using wildcards. I have tried using Xpath but no success. Essentially, I want to select all the nodes with attributes beginning with a certain string eg) Wanted[…., regardless of the remaining text in the attribute name field.
Can anybody please kindly point to me how to go about doing it if possible? Any advice will be greatly appreciated.
Below are sample of my code and xml file.
reader = new XmlTextReader(link);
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
if (reader.Name == "A") //To select some nodes w/o attributes
{…. }
if (reader.MoveToFirstAttribute()) {
switch (reader.GetAttribute(0)) //To select somes nodes based on attributes.
{
case "Wanted[zxx]":
…
break;
case "Wanted[yyy]":
…
…
default:
break;
….
- <Root>
<A>XXX</A>
….
- <Elements>
<Element name="Num">XXX</Element>
<Element name="xxx">xxx</Element>
<Element name="B1">1424</Element>
<Element name="Unwanted1">xxx</Element>
<Element name="Unwanted2">xxx</Element>
<Element name="Wanted[XXX]">xxx</Element>
<Element name="Wanted[YYY]">xxx</Element>
<Element name="Wanted[ZZZ]">xxx</Element>
</Elements>
</Root>
|
|
|
|
|
drifters wrote: Now, I would like to know if there are ways to select the nodes based on part of its attribute name like using wildcards.
I don't think so.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Oh no. If that's the case than I'll have to hardcode the cases. Thanks for the help. Any other view or advice will be greatly appreciated.
|
|
|
|
|
Hi!
Im currently playing around with making a Keylogger (nothing malicious, I promise) and ive gotten everything to work properly thus far, but one feature I think would be helpful would be recognizing what window currently has focus for each keystroke, i.e. if "hello" is typed in an internet explorer window, and then "c# programming" is typed in a firefox window, is there any way for my application to both get the kaystrokes, and the window with focus... making me able to do something like this:
Internet Explorer - The Code Project:
hello
Mozilla Firefox - The Code Project:
c# programming
Hopefully ive been clear on what I would like, any help would be much appreciated. Thanks!
Dirk Williams
|
|
|
|
|
Hi,
you can get a window handle and then either get the window's title, or scan the
process list (Process class) to find the process it belongs to. Some PInvoke
would be required:
[DllImport("user32")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
public static extern void GetWindowText(IntPtr hWnd, StringBuilder sb, int capacity);
|
|
|
|
|
Hello everyone,
I am using the following code to specify a window to receive mouse and keyboard messages from the video window.
IVideoWindow.put_MessageDrain(this.DvdPanel.Handle);
I was wondering if I can do the following:
1- Can I distinguish between the right and the left mouse click?
2- Can I assign seprerate events to the mouse clicks?
- I would like to have ContextMenu once the right mouse is clicked; and follow the menu available on the Video Window once the left mouse is clicked.
Thank you very much and have a great day.
Khoramdin
|
|
|
|
|
What is an IVideoWindow ?
1 - in your event handler, you can. It's part of the event args
2 - no
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Helo Christian,
Thank you for your help. IVideoWindow is a DirectShow Interface. It is used for rendering Video images. If I am not mistaken your answer still stays the same regarding the mouse click. As I mentioned I can detect mouse click but I am unable to seperate the Left from Right mouse click.
Thank you very much for your help and have a great day.
Khoramdin
|
|
|
|
|
hi all,
let's say i have the following code:
public void GetAuthors_Click(Object sender, EventArgs E) <br />
{<br />
String selectCmd = "select * from Authors where state = @State";<br />
<br />
SqlConnection myConnection = new SqlConnection("server=(local)\\NetSDK;database=pubs;Trusted_Connection=yes");<br />
SqlDataAdapter myCommand = new SqlDataAdapter(selectCmd, myConnection);<br />
<br />
myCommand.SelectCommand.Parameters.Add(new SqlParameter("@State", SqlDbType.NVarChar, 2)); myCommand.SelectCommand.Parameters["@State"].Value = MySelect.Value;<br />
<br />
DataSet ds = new DataSet();<br />
myCommand.Fill(ds, "Authors");<br />
<br />
MyDataGrid.DataSource= ds.Tables["Authors"].DefaultView;<br />
MyDataGrid.DataBind();<br />
}
there is a text file i read with lines as follows:
DECLARE @VAR0 VARCHAR(40) --Variable0<br />
DECLARE @VAR1 INT --Variable1<br />
DECLARE @VAR2 BIT --Variable2
such that the second column gets stored in string[] strVarNames (i.e. strVarNames[1] = "@VAR1")
third column gets stored in string[] strVarTypes (i.e. strVarTypes[1] = "INT")
my question is in the following line from the above code:
myCommand.SelectCommand.Parameters.Add(new SqlParameter("@State", SqlDbType.NVarChar, 1));
how do i replace the 2nd parameter type as in the following example?
myCommand.SelectCommand.Parameters.Add(new SqlParameter(strVarNames[1], ***HOW from strVarTypes[1]?***, 1));
Thank you in advance.
I am a SysAdmin, I battle my own daemons.
|
|
|
|
|
First of all, please tell me you're not really putting all this code in your click event handler ?
Basically, if you have a string representation of the type, you probably need to write a switch statement that works out what type to return, or you may be able to use reflection.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I can't figure out the Mesh.Save() method. Does anyone know how to use this properly? I want to save my mesh data to a .x file so that I can use it in other programs, but I can't figure out this method.
-----
Note: *** Never give me an answer have anything to do with Visual Studio. I don't have this program, and it'll be that way for a long, long time. ***
|
|
|
|
|
What API are you using? (Managed DX? XNA?)
p.s. your signature sounds like something heard from a whiny slashdot linux fanboy. It discourages me, and probably others, from replying to your posts.
|
|
|
|
|
hello everybody,
I'm currently writing an Poker Odds Calculator.
I want this programm to read some informations from Online Poker Rooms like Pokerstars or PartyPoker. But the big problem that I have right now is that I dont know how to collect this Informations (like what text is stored in a textbox...) and transfer it to my Application so that I can calculate with it.
I searched the Internet but I didnt find anything.
Can you give me some inspirations?
This would be very great.
|
|
|
|
|
Do PartyPoker et al have a public API you could code against?
If not, you're left to stealing info from a behind-the-scenes browser (think System.Windows.Forms.WebBrowser). Such is possible, but not recommended because of difficulty and fragility, not to mention it's probably on shaky legal grounds.
|
|
|
|
|