|
miles.smith wrote: I would like to be able to dynamically identify how many threads I want the the application to use.
Based on what? What criteria do you think you will be using to make that determination?
miles.smith wrote: so I need a new thread for each function.
No, what you need is to do some reading on the subject of multi-thread application development. I don't know what current sources there are but years ago I found Advanced Windows by Richter to be a valuable resource on the subject of multi-threading
led mike
|
|
|
|
|
Okay, I'll go do some reading up on that. It seems like I'm not understanding what my requirements are!
Thanks.
|
|
|
|
|
miles.smith wrote: Okay, I'll go do some reading up on that.
Excellent decision, there is hope for you. Don't expect miracles though. The subject can be rather elusive. Take your time, it's worth getting it right.
led mike
|
|
|
|
|
Hello,
Can anybody give me link or provide sample source as how to let EMAB know about the newly added custom Exception Handler class without adding it to configuration file?
Enterprise library depends on Configuration file settings to know about any new custom Exception Handlers, which as a developer we need to configure (add using EL Configuration Console). But i don't want to do that, i just want EMAB to pickup the Class implementing IExceptionHandler from current Assembly.
Thanks
|
|
|
|
|
hi guys i was wondering if you could help me out please, i have been stuck at this for a few days...
I am using the Intel Mobile SDK to monitor Power and Cononnectivty, i can monitor them and log the results in the console, but i would like to migrate it to log in a text box in the form?
below is my program, could sumbody help me out please, or if sumbody could point in the right direction, many thanks.
using System;
using System.Threading;
using Intel.Mobile.Base;
using Intel.Mobile.Battery;
using Intel.Mobile.Context;
namespace Sample
{
public class ConnectEventSample
{
internal static bool LoopFlag = true;
internal static readonly System.Object Mutex = new System.Object();
[MTAThread]
static void Main(string[] args)
{
try
{
ContextClass myClass = new ContextClass();
PowerInstance myInstance = (PowerInstance)myClass.GetInstance("Power");
ConnectivityInstance myInstance2 = (ConnectivityInstance)myClass.GetInstance("Connectivity");
Observer ConnectObserver = new ConnectObserver();
Observer DisconnectObserver = new DisconnectObserver();
Observer ConnectObserver2 = new ConnectObserver2();
Observer DisconnectObserver2 = new DisconnectObserver2();
myInstance.ExternallyPowered.AddObserver(ConnectObserver);
myInstance.InternallyPowered.AddObserver(DisconnectObserver);
myInstance2.Connected.AddObserver(ConnectObserver2);
myInstance2.Disconnected.AddObserver(DisconnectObserver2);
Console.WriteLine("------------ Waiting for Event ------------");
bool bContinue;
do
{
// Wait for Connect event.
// The network cable may be plugged in to trigger this event.
// yield a few CPU cycles
//Thread.Sleep(500);
lock (Mutex)
{
bContinue = LoopFlag;
}
}
while (bContinue == true);
//myInstance.ExternallyPowered.AddObserver(ConnectObserver);
//myInstance.InternallyPowered.AddObserver(DisconnectObserver);
//myInstance2.Connected.AddObserver(ConnectObserver2);
//myInstance2.Disconnected.AddObserver(DisconnectObserver2);
myInstance.ExternallyPowered.RemoveObserver(ConnectObserver);
myInstance.InternallyPowered.RemoveObserver(DisconnectObserver);
myInstance2.Connected.RemoveObserver(ConnectObserver2);
myInstance2.Disconnected.RemoveObserver(DisconnectObserver2);
ConnectObserver.Close();
DisconnectObserver.Close();
ConnectObserver2.Close();
DisconnectObserver2.Close();
}
catch (IntelMobileException ex)
{
Console.WriteLine("------------ Exception Occurred ------------");
Console.WriteLine("Message: " + ex.Message);
Console.WriteLine("Source: " + ex.Source);
Console.WriteLine("Target Site: " + ex.TargetSite);
Console.WriteLine("Error Code: " + ex.ErrorCode);
Console.WriteLine("Detailed Error Info: " + ex.DetailErrorInfo);
}
catch ( Exception e)
{
Console.WriteLine("------------ Exception Occurred ------------");
Console.WriteLine("Message: " + e.Message);
Console.WriteLine("Source: " + e.Source);
Console.WriteLine("Target Site: " + e.TargetSite);
}
//Console.Write("Press 'Enter' to exit...");
//Console.Read();
}
}
internal class ConnectObserver : Observer
{
public override void Notify(Event ev)
{
try
{
if (ev.GetType() == EventBase.EventType.eExternallyPowered)
//Console.WriteLine("{0} Connected event occurred for {1}", ev.GetTSstring(), ev.GetOriginator().GetType());
Console.WriteLine("AC Adapter Connected - Running on External Power " + DateTime.Now);
}
catch (IntelMobileException ex)
{
Console.WriteLine(ex);
}
catch (Exception e)
{
Console.WriteLine("------------ Exception Occurred ------------");
Console.WriteLine("Message: " + e.Message);
Console.WriteLine("Source: " + e.Source);
Console.WriteLine("Target Site: " + e.TargetSite);
}
// Reset flag to exit event wait loop
//lock (ConnectEventSample.Mutex)
//{
// ConnectEventSample.LoopFlag = false;
//}
}
}
internal class DisconnectObserver : Observer
{
public override void Notify(Event ev)
{
try
{
if (ev.GetType() == EventBase.EventType.eInternallyPowered)
//Console.WriteLine("{0} Connected event occurred for {1}", ev.GetTSstring(), ev.GetOriginator().GetType());
Console.WriteLine("AC Adapter Disconncted - Running on battery " + DateTime.Now);
}
catch (IntelMobileException ex)
{
Console.WriteLine(ex);
}
catch (Exception e)
{
Console.WriteLine("------------ Exception Occurred ------------");
Console.WriteLine("Message: " + e.Message);
Console.WriteLine("Source: " + e.Source);
Console.WriteLine("Target Site: " + e.TargetSite);
}
// Reset flag to exit event wait loop
//lock (ConnectEventSample.Mutex)
//{
// ConnectEventSample.LoopFlag = false;
//}
}
}
internal class ConnectObserver2 : Observer
{
public override void Notify(Event ev)
{
try
{
if (ev.GetType() == EventBase.EventType.eConnected)
{
//Console.WriteLine("{0} Disconnected event occurred for {1}", ev.GetTSstring(), ev.GetOriginator().GetType());
Console.WriteLine("Connected to Network at " + DateTime.Now);
}
}
catch (IntelMobileException ex)
{
Console.WriteLine(ex);
}
catch (Exception e)
{
Console.WriteLine("------------ Exception Occurred ------------");
Console.WriteLine("Message: " + e.Message);
Console.WriteLine("Source: " + e.Source);
Console.WriteLine("Target Site: " + e.TargetSite);
}
}
}
internal class DisconnectObserver2 : Observer
{
public override void Notify(Event ev)
{
try
{
if (ev.GetType() == EventBase.EventType.eDisconnected)
{
//Console.WriteLine("{0} Disconnected event occurred for {1}", ev.GetTSstring(), ev.GetOriginator().GetType());
Console.WriteLine("Disconnected from Network at " + DateTime.Now);
}
}
catch (IntelMobileException ex)
{
Console.WriteLine(ex);
}
catch (Exception e)
{
Console.WriteLine("------------ Exception Occurred ------------");
Console.WriteLine("Message: " + e.Message);
Console.WriteLine("Source: " + e.Source);
Console.WriteLine("Target Site: " + e.TargetSite);
}
}
}
}
|
|
|
|
|
Be aware that adding to a textbox with alot of text in it is a very slow operation. You'll want to keep the buffer displayed in it very short to keep CPU usage reasonable.
Otherwise [Microsoft is] toast in the long term no matter how much money they've got. They would be already if the Linux community didn't have it's head so firmly up it's own command line buffer that it looks like taking 15 years to find the desktop.
-- Matthew Faithfull
|
|
|
|
|
is there a way to get it working, it aint going into production, its just to show that it can be done
is there a way to log a few events into the txt file the way the console logs thems
thanks
|
|
|
|
|
yes. Instead of writing to the console write to the file.
Otherwise [Microsoft is] toast in the long term no matter how much money they've got. They would be already if the Linux community didn't have it's head so firmly up it's own command line buffer that it looks like taking 15 years to find the desktop.
-- Matthew Faithfull
|
|
|
|
|
Hi,
does anyone know where i can get a Led UI Control???
or how can i create one using the usercontrol (my led needs to be Round)
THNKAS
Have Fun
Never forget it
|
|
|
|
|
half-life wrote: how can i create one
half-life wrote: my led needs to be Round
Do you know how to paint a filled circle?
led mike
|
|
|
|
|
Maybe half-life needs to simulate the luminous efficacy, light wavelength, and viewing angle of a Real LEDTM?
|
|
|
|
|
Bingo, yes thats it
i know it's sound crazy but the answer is YEP
Have Fun
Never forget it
|
|
|
|
|
yes of course i can
but it's more complexed then just a simple circle
i know how to change the region using GraphicPath and etc.
but juat as Brady Kelly said there are motr things to it
and i do not know how to make it 3D
(can i use the borderstyle of the usercontrol and combine it with the region?)
THANKs
Have Fun
Never forget it
|
|
|
|
|
A search for "LED" in C# articles revealed the following:/ravi
|
|
|
|
|
THANKS
Have Fun
Never forget it
|
|
|
|
|
Hi,
I am using the following codes to update an excel spreadsheet:
The problem is that I have to do this update for hundreds of records with different Security_IDs and it takes about 2 seconds per record to update. i.e. command.ExecuteNonQuery(); takes about 2 seconds for each update.
How can I modify this code to do all these updates quickly?
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MarketAnalytics\YieldsSpreads\YieldsSpreads.xls;Extended Properties=""Excel 8.0;HDR=YES;""";
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
using (DbConnection connection = factory.CreateConnection())
{
connection.ConnectionString = connectionString;
using (DbCommand command = connection.CreateCommand())
{
command.CommandText = @"Update [Allbonds$] Set Bid_Price = '" + strBid_Price_Best_Latest + "', Ask_Price = '" + strAsk_Price_Best_Latest + "' WHERE Security_ID = " + strSecurity_ID;
command.CommandText = strSQL;
connection.Open();
command.ExecuteNonQuery();
}
}
|
|
|
|
|
to start, how about reusing one DB connection instead of creating a new one for each record, and don't forget to Close your connection, either . . .
|
|
|
|
|
This is my exact code.
can you see where to change it to the way you suggeste please?
I am looping through a datagridview control and for each record in the control I am updating the excel sheet.
try
{
//get prices for securities...
int intSecurity_IDColumn = dgvSecurityPricing.Columns["Security_ID"].Index;
int intSecurity_NameColumn = dgvSecurityPricing.Columns["Security_Name"].Index;
int intBid_Price_Best_LatestColumn = dgvSecurityPricing.Columns["Bid_Price_Best_Latest"].Index;
int intAsk_Price_Best_LatestColumn = dgvSecurityPricing.Columns["Ask_Price_Best_Latest"].Index;
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MarketAnalytics\YieldsSpreads\YieldsSpreads.xls;Extended Properties=""Excel 8.0;HDR=YES;""";
foreach (DataGridViewRow row in dgvSecurityPricing.Rows)
{
string strSecurity_ID = row.Cells[intSecurity_IDColumn].Value.ToString();
string strSecurity_Name = row.Cells[intSecurity_NameColumn].Value.ToString();
string strBid_Price_Best_Latest = row.Cells[intBid_Price_Best_LatestColumn].Value.ToString();
string strAsk_Price_Best_Latest = row.Cells[intAsk_Price_Best_LatestColumn].Value.ToString();
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
using (DbConnection connection = factory.CreateConnection())
{
connection.ConnectionString = connectionString;
using (DbCommand command = connection.CreateCommand())
{
//only send prices if there is one...
string strSQL = "";
if (strBid_Price_Best_Latest.Length > 0 && strAsk_Price_Best_Latest.Length > 0)
{
strSQL = @"Update [Allbonds$] Set Bid_Price = '" + strBid_Price_Best_Latest + "', Ask_Price = '" + strAsk_Price_Best_Latest + "' WHERE Security_ID = " + strSecurity_ID;
}
if (strBid_Price_Best_Latest.Length > 0 && strAsk_Price_Best_Latest.Length == 0)
{
strSQL = @"Update [Allbonds$] Set Bid_Price = '" + strBid_Price_Best_Latest + "', Ask_Price = 0 WHERE Security_ID = " + strSecurity_ID;
}
if (strBid_Price_Best_Latest.Length == 0 && strAsk_Price_Best_Latest.Length > 0)
{
strSQL = @"Update [Allbonds$] Set Bid_Price = 0, Ask_Price = '" + strAsk_Price_Best_Latest + "' WHERE Security_ID = " + strSecurity_ID;
}
if (strBid_Price_Best_Latest.Length == 0 && strAsk_Price_Best_Latest.Length == 0)
{
strSQL = @"Update [Allbonds$] Set Bid_Price = 0, Ask_Price = 0 WHERE Security_ID = " + strSecurity_ID;
}
//command.CommandText = @"Update [Allbonds$] Set Bid_Price = '" + strBid_Price_Best_Latest + "', Ask_Price = '" + strAsk_Price_Best_Latest + "' WHERE Security_ID = " + strSecurity_ID;
command.CommandText = strSQL;
//Console.WriteLine(strSQL);
connection.Open();
command.ExecuteNonQuery();
}
}
}
}
|
|
|
|
|
move the
arkiboys wrote: foreach (DataGridViewRow row in dgvSecurityPricing.Rows)
loop inside of the
arkiboys wrote: using (DbCommand command = connection.CreateCommand())
statement. That way you're creating a new SQL command string for each row in the datagrid and using the same DbConnection and DbCommand objects over and over again instead of destroying them after each row is updated
p.s. put < pre > tags around your code in posts to preserve the formatting, that'll make it easier on the eyes Last modified: 21mins after originally posted --
|
|
|
|
|
that if block where you assign strSQL is pretty inefficient in itself. There are two basic conditions that are being tested:
1) strBid_Price_Best_Latest.Length > 0
2) strAsk_Price_Best_Latest.Length > 0
but each variable is compared with zero 4 different times using different operators. That whole block can be reduced to 3 comparisons (down from 8) with the use of else blocks:
if (strBid_Price_Best_Latest.Length > 0)
{
if (strAsk_Price_Best_Latest.Length > 0)
{
strSQL = @"Update [Allbonds$] Set Bid_Price = '" + strBid_Price_Best_Latest + "', Ask_Price = '" + strAsk_Price_Best_Latest + "' WHERE Security_ID = " + strSecurity_ID;
}
else
{
strSQL = @"Update [Allbonds$] Set Bid_Price = '" + strBid_Price_Best_Latest + "', Ask_Price = 0 WHERE Security_ID = " + strSecurity_ID;
}
}
else
{
if (strAsk_Price_Best_Latest.Length > 0)
{
strSQL = @"Update [Allbonds$] Set Bid_Price = 0, Ask_Price = '" + strAsk_Price_Best_Latest + "' WHERE Security_ID = " + strSecurity_ID;
}
else
{
strSQL = @"Update [Allbonds$] Set Bid_Price = 0, Ask_Price = 0 WHERE Security_ID = " + strSecurity_ID;
}
}
Also, if you have "System.Data.OleDb" hardcoded in your program, then why use a Factory method to get your DB connection? You could just use OleDbConnection and OleDbCommand objects instead . . .
In other news, I'm having a very slow day at work
|
|
|
|
|
|
Hi all.
I have to read from oracle data base large amount of data (about 5000 records), and i use for this purpose standard procedure
oraDataTableAdapter.Fill(oraDataTable)
, but this working very slow (about 15 seconds). In other side when i fill data table from MS SQL (with same number of records) its occupied mach less time. How i can to decrease time consumption for this operation for Oracle.
THANK
|
|
|
|
|
Convert to SQL Server
only two letters away from being an asset
|
|
|
|
|
5000 records isn't really that much data, even a whole second would be too slow for getting the data.
Do you have any means of running the query in a management tool in the database, so that you see if the query itself is slow, or the transfer to the DataTable.
If the query itself is slow, check if you have indexes on the appropriate fields in the database tables.
If the transfer is slow, check your connection string. On connectionstrings.com[^] you can find examples of connection strings for several different purposes.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Thank
Query work fine in managment tool. As such as i think that problem in Oracle framework.
And how connection string can affect speed of data retriving????
|
|
|
|