|
Have you tried running the proc in query analyser with the EXACT paramters you are passing? Its often easy to get a trailng space on a string that results in no data, or similar problems. I often just do a bit of code to generate the exact call (with the param values in the correct quites etc), then test it in query analyser.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hi
I have a project where I want to start X threads for processing in the background while the main thread does other stuff. However, as soon as the main thread is finished with its work it should wait for all the other threads to finish before continue.
I looked at threadpool and found it to be insufficient (due to reasons I will not discuss here).
What I try instead is to implement my own pool of threads starting with:
Thread[] threads = new Thread[numthreads];
for (int i = 0; i < this.threads.Length; i++)
{
threads[i] = new Thread(Handler);
threads[i].Start();
}
I figured I could use ManualResetEvent to wait for the threads to finish. My question is this though:
Can I use a single resetevent for all threads to signal, or do I really need to have <numthreads> resetevents and use WaitHandle.WaitAll()?
How about the other way around? Can I have a single resetevent that all threads are listening to (waiting for input to process), and then only the first thread to catch the signal from the mainthread to actually start processing?
|
|
|
|
|
If your worker threads are terminating after they have done their work, you can just use Thread.Join on each one from your main thread.
If they stay around in a loop, waiting for the next batch of work, then you need a Barrier ( not a memory barrier - that's something different ). As it happens, I've just been playing with the new Barrier class in .NET 4.0, but I guess that doesn't help you much
The easiest way to implement this at the moment, is to have an int that you set to your numthreads before you start the threads. When each thread finishes its work, it calls Interlocked.Decrement and if it is the last thread, it signals an AutoResetEvent that the main thread is waiting on.
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
I'm having an odd issue that appears to have cropped up out of nowhere.
I have a program that uses a plugin interface to add separate modules. I have the main application project, and main function library, and about 6 plugins. In the library, I've defined a Global class to access a few static variables. I needed a dispatcher reference, so I added a static variable in the Global class, which is then set when the main application starts up. The plugins will often then use this variable when they need a dispatcher and none is available.
Originally, this all worked fine, and I haven't changed anything in the Global class; however, now, none of the plugins can see the value of the static variable. I did a little testing, and was able to find this:
If I declare a variable, but don't set a value in the Global class; but then give it a value in the Main Application, it comes up as null when read by a plugin. I have:
In the Global class:
public static string Test;
In Window_Loaded for main app:
Global.Test = "Test";
When checking in a plugin:
MessageBox.Show(Global.Test);
it returns null. I do have a reference to the Global class in the plugin.
If I set the value in the declaration in the Global class it works fine:
In the Global Class:
public stating string Test = "Test";
If I then add this to the Window_Loaded of the main app:
Globa.Test = "MyNewTest";
In the plugin, it displays "Test", even though it was previously set to "MyNewTest" at startup.
I have also checked the value from the main app - checking the value at anytime in the main app returns the correct "MyNewTest".
It appears that when the variable is assigned a value from the main application project, it is not accessible from any of the plugin projects (all different classes, of course).
As I mentioned, this previously worked fine, and I haven't altered the Global class. Additionally, I've also checked plugins that I haven't changed, and they don't seem to work now either, even though none of the components have changed (I've added new plugins, but checking the main app, the Global class and a plugin, all of which have not changed, still show this issue).
Any insight on this would be greatly appreciated.
Thanks,
Mike
|
|
|
|
|
Do you use multiple threads? If yes, you may try to use the volatile keyword for the variable:
public static volatile string Test;
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I am using multiple threads. I tried using the volatile keyword, and no such luck. It almost looks like it is accessing another instance of the static variable.
If it helps, in my testing, all 3 parts (declaring the variable, setting it and calling it) are all happening in the same thread.
It holds the value up until I get to the plugin, then it reverts to whatever the constructor is (or null if the variable is not explicitly defined at declaration). This is what led me to believe perhaps it is accessing another instance of the static variable (which shouldn't be possible, as far as I understand.)
Thanks for any insight,
Mike
|
|
|
|
|
I have two databases (I'll call them (A) and (B) for this discussion) that keep Customer information. (A) uses a system generated integer for the unique record ID and (B) uses its Company_Code and Customer_Code data fields as its unique record ID. I can change the database structure for (A) but not (B). I added Company_Code and Customer_Code fields to (A) so I can relate (A) and (B) customer records. If i'm working in a child record in (A) I know the interger for the customer, but I have to query the parent for the (B) key when I need information from (B). If i'm working in (B) I know the Company_Code, Customer_Code, but again, I have to query (A) parent record to get the correct integer value if I need information from (A). So I came up with the following solution that I need help with. (I should mention I'm a newbie programmer and would gladly consider other solutions)
1. I created a simple class:
public class CustomerIDPair: IComparer<CustomerIDPair>, IComparable<CustomerIDPair>
{
private string _company_Code = string.Empty;
private string _customer_Code = string.Empty;
public CustomerIDPair()
{
}
public CustomerIDPair(string Company_Code, string Customer_Code)
{
_company_Code = Company_Code;
_customer_Code = Customer_Code;
}
public string Company_Code
{
get { return _company_Code; }
set { _company_Code = value; }
}
public string Customer_Code
{
get { return _customer_Code; }
set { _customer_Code = value; }
}
public override string ToString()
{
return _company_Code.Trim() + ", " + _customer_Code.Trim();
}
#region IComparer<CustomerIDPair> Members
public int Compare(CustomerIDPair x, CustomerIDPair y)
{
string strX = x.Company_Code.Trim().PadLeft(3) + x.Customer_Code.Trim().PadLeft(10);
string strY = y.Company_Code.Trim().PadLeft(3) + y.Customer_Code.Trim().PadLeft(10);
return string.Compare(strX, strY, true);
}
#endregion
#region IComparable<CustomerIDPair> Members
public int CompareTo(CustomerIDPair other)
{
string strX = this.Company_Code.Trim().PadLeft(3) + this.Customer_Code.Trim().PadLeft(10);
string strY = other.Company_Code.Trim().PadLeft(3) + other.Customer_Code.Trim().PadLeft(10);
return string.Compare(strX, strY, true);
}
#endregion
}
2. I created 2 Dictionarys 'AtoB<int, CustomerIDPair>' and 'BtoA<CustomerIDPair, int>' , then populated them from A on application startup
Assume there is a customer that is identified in A as 14, and identifed as "EZE","TLC" in B
So:
AtoB[14] correctly evalates to a CustomerIDPair from with I can retrieve the company_Code and customer_Code.
But:
CustomerIDPair custID = new CustomerIDPair("EZE","TLC");
int test = BtoA[custId];
raises a KeyNotFoundException
Does anyone have any ideas how to make this work?
Thanks in advance
Russ
|
|
|
|
|
ret7679 wrote: But:
CustomerIDPair custID = new CustomerIDPair("EZE","TLC");
int test = BtoA[custId];
raises a KeyNotFoundException
This totally makes sense: you create a new CustomerIDPair object and try to locate it in the dictionary. But since you haven't added the newly created CustomerIDPair to the dictionary it simply doesn't exist there.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
There is a CustomerIDPair in the BtoA Dictionary whose Company_Code is "EZE" and whose Customer_Code is "TLC" which was added when I created and populated the Dictionary. The problem seems to be in equating this new CustomerIDPair with the original.
|
|
|
|
|
You probably want something like this:
int id = -1;
foreach (CustomerIDPair pair in BtoA.Keys)
{
if (pair.Company_Code.Equals("EZE") && pair.Customer_Code.Equals("TLC"))
{
id = BtoA[pair];
break;
}
}
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Trying to delete duplicated data form a database.
I only need to delete specific information from a databae
var conn = new SqlConnection("Data Source =(local)\\Openhouse;" + ";Initial Catalog=" + _sqlDBName + ";Integrated Security=SSPI");
conn.Open();
var dataAdapter = new SqlDataAdapter();
var command = new SqlCommand(select, conn);
dataAdapter.SelectCommand= command;
var conDS = new ContactDs();
SqlCommand sqlcmd = conn.CreateCommand();
sqlcmd.CommandText = "DELETE FROM Contact WHERE IDNumber != '156' AND Quality = '40'";
dataAdapter.Fill(conDS, "Contact");
dataAdapter.DeleteCommand = sqlcmd;
dataAdapter.Update(conDS, "Contact");
private string select = "SELECT * FROM Contact";
Note I only need to delete information form this table and these columns. tested on sql server with studio manager works fine have problem in c# code.
Learning to Code
|
|
|
|
|
Could you be more descriptive about the problems you encounters?
Btw, var is not a C# keyword.
|
|
|
|
|
Le Centriste wrote: Btw, var is not a C# keyword.
Actually it is, in C# 3.5 and later.
However, I have seldom seen it more misused. The coder has obviously not read the documentation:
"Overuse of var can make source code less readable for others. It is recommended to use var only when it is necessary, that is, when the variable will be used to store an anonymous type or a collection of anonymous types."
Or perhaps he has chosen to totally disregard this recommendation.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: Or perhaps he has chosen to totally disregard this recommendation.
Something we rarely see in real-life code.
|
|
|
|
|
Mo John wrote: conn.Open();
var dataAdapter = new SqlDataAdapter();
var command = new SqlCommand(select, conn);
dataAdapter.SelectCommand= command;
You don't need a data adapter to put the command in.
Mo John wrote: var conDS = new ContactDs();
You don't need a data set when you are not reading data.
Mo John wrote: dataAdapter.Fill(conDS, "Contact");
dataAdapter.DeleteCommand = sqlcmd;
dataAdapter.Update(conDS, "Contact");
There is no reason to read the data into a data set, as you are not using any of it. Also, setting the DeleteCommand property doesn't actually delete anything, it only specifies what to use when something is deleted.
Just execute the command:
using (SqlCommection conn = new SqlConnection("Data Source =(local)\\Openhouse;Initial Catalog=" + _sqlDBName + ";Integrated Security=SSPI")) {
SqlCommand command = new SqlCommand("DELETE FROM Contact WHERE IDNumber != '156' AND Quality = '40'", conn);
conn.Open();
command.ExecuteNonQuery();
}
Note: These five lines replaces all of your code. It also closes the database connection, which you didn't do in your code.
Are the IDNumber and Quality fields really text fields? If they are not, you should use numeric literals instead of string literals in the condition.
Although the != operator is supported by T-SQL, the <> operator is more widely known, and is supported by all SQL implementations.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
thanks I fiqure out with help form msdn
Learning to Code
|
|
|
|
|
Hi,
I made a Form derivated class and I'd like to put some code in the Load event so when I use it, it will get the application icon (if any) and show it in the top left corner (as any windows software). I saw I few methods but they assume I know the namespace and the icon name, but as I told you the form may be used in any application, so I have to find out those informations too...
Thanks,
Dirso
|
|
|
|
|
Dirso wrote: it will get the application icon (if any) and show it in the top left corner
An application can have many icons, which one do you want?
Dirso wrote: I saw I few methods but they assume I know the namespace and the icon name
Well, that's because you have to choose between the many potential icons that may exist in your application.
Dirso wrote: as I told you the form may be used in any application
Actually, you didn't. This is the first time you mentioned that piece of information.
|
|
|
|
|
Hi,
I want the main application icon. That one you choose in the application property window.
Thanks,
Dirso.
|
|
|
|
|
Try putting the following code in the constructor for your form. It should pick up the Icon for any app in which it is included.
<br />
this.Icon = Icon.ExtractAssociatedIcon(System.Reflection.Assembly.GetEntryAssembly().Location);<br />
Henry Minute
If you open a can of worms, any valid solution *MUST* involve a larger can!
|
|
|
|
|
It worked like a charm!!! Thank you so much!!!
|
|
|
|
|
how do you open the file browser dailog Using "Open" button click
|
|
|
|
|
craigMUTOKOKAI wrote: how do you open the file browser dailog Using "Open" button click
The same way as you'd handle any button click event.
In your event handler code you need to create an OpenFileDialog, set it up as you want (or not, if you are happy with the default behaviour) and then call ShowDialog() on it.
The DialogResult will indicate whether the user Cancelled the dialog or not.
|
|
|
|
|
DialogResult DialogResult_Logout = MessageBox.Show("Do you want to logout and return to Page Login?", "Logout", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (DialogResult_Logout == DialogResult.Yes)
{
UserControl_PageLogin_Visible(true);
}
Is this what you want?
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
Hello all,
can any body tell me how to release resources hold by thread before aborting it?
Is there a way to check what resources a thread is holding?
Thanks
|
|
|
|
|