|
Thanks for your reply.
Can I have a list of SqlConnection, SqlDataReader & SqlCommand?
Eg: List<SqlConnection> SQLConnections = new <SqlConnection>();
|
|
|
|
|
Sure you can, but I recommend making a class that holds a Connection, a Command, and a DataReader -- then make a list of those.
|
|
|
|
|
Thanks a ton..
|
|
|
|
|
I think you're trying to solve a problem that doesn't exist. The DataReader portion of the code is very fast (assuming you aren't overusing .ToString() . The expense is executing the query itself and getting the data back over the wire.
If you want to process the data in different threads, thats a different story. Use ONE DataReader and dump the data into a List. Then use Parallel.ForEach on the List.
|
|
|
|
|
Thanks for the information. If I am not wrong, this command is available for .NET 4 and above.
If yes, then it might not work for me as I am working on 3.5.
Please Advise.
-- modified 16-Jan-15 13:00pm.
|
|
|
|
|
Well, you can use multi-threading on the List in 3.5 without the Parallel.ForEach.
Parallel.ForEach just makes it trivial and handles everything for you. As Pie mentioned, is it a lot of data? If its not a lot of data, just expensive processing, I'd dump it in a List and multi-thread process the List. If it is a lot of data, are you sure you need all that data at once?
If its a lot of data AND you need it all at once, can you limit your app to run on a 64-bit OS? If so, memory won't really be an issue (as long as your machine has enough RAM).
If its a lot of data AND you need it all at once AND you can't restrict to a 64-bit OS AND/OR it would be too much data to keep in memory, etc. and you really need to do the multi-threaded reader approach, is the data coming from a table or pre-computed? If so, you could have a paging approach.... have each reader grab x records on its own connection, etc, but that approach will kill performance as calling a SP and spinning up the connection and disposing it is relatively expensive.
|
|
|
|
|
If it's tons of data I wouldn't want to hold it all in memory without good reason.
(And it doesn't look like threading.)
|
|
|
|
|
From his original post, it looks like he is trying to implement multi-threaded processing of the table, just in the wrong way.
|
|
|
|
|
I considered that, but I don't think so. Of course, the situation is unclear.
|
|
|
|
|
Here is my xml file i want to get the value of contextExpression eg.
I have tried lots of example to get the value but failed
Can anybody help to how to do using XDocument in C#
modified 15-Jan-15 11:24am.
|
|
|
|
|
|
Try this:
XDocument document = XDocument.Parse(@"<?xml version=""1.0"" encoding=""utf-8""?>
<campaign xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""urn:nds:dyn:campaign:version02"" handle=""4329"" campaignId=""4329"" campaignType=""EPG"" startDateTime=""2015-01-15T10:07:51"" endDateTime=""2015-01-15T12:07:51"" lastModifiedDateTime=""2014-10-25T06:24:28"" amsEnabled=""false"">
<contextExpression><![CDATA[(zoneId==176)&&((startTime==100)&&(endTime==1200))]]></contextExpression>
<adContent>
<contentInstance xsi:type=""ImageInstanceType"" language=""English"" imageType=""PNG"" height=""228"" width=""178"" epgResolution=""HD"">
<contentInstanceRef>image.png</contentInstanceRef>
</contentInstance>
</adContent>
</campaign>");
XNamespace defaultNamespace = document.Root.Name.Namespace;
XName contextExpressionNodeName = defaultNamespace + "contextExpression";
XElement contextExpressionNode = document.Root.Element(contextExpressionNodeName);
string contextExpression = (string)contextExpressionNode;
Console.WriteLine(contextExpression);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
So, I have an enum and want to get the ASCII code of the numeric value of a certain enum value. For example if I have the enum value STANDARD (=1), I want to get the ASCII code for '1' (49) in a byte variable. I cant seem to figure out how to do. Anyone?
enum PackageType : byte { STANDARD=1, REQUEST=2, ANSWER=3 }
PackageType type = PackageType.STANDARD;
byte b = (byte)type;
|
|
|
|
|
|
"How about make STANDARD=49 ?"
Well, I guess it´s time to call it a night. Lol
I´ll make STANDARD=49.
|
|
|
|
|
((int)type).ToString();
Or, if you want just the first character:
((int)type).ToString()[0];
The difficult we do right away...
...the impossible takes slightly longer.
modified 14-Jan-15 15:13pm.
|
|
|
|
|
|
Well if you can change you enum you could do this:
enum PackageType
{
Standard = '1',
Request = '2',
Answer = '3'
}
And that's job done. If not, just add 48 to 'b'.
Regards,
Rob Philpott.
|
|
|
|
|
Yet another option would be a conversion function as follows:
enum PackageType : byte { STANDARD, REQUEST, ANSWER }
static readonly byte[] PackageTypeValues = { (byte)'1', (byte)'2', (byte)'3' };
byte PackageTypeToByte( PackageType packageType )
{
return PackageTypeValues[(byte)packageType];
}
This has the advantage of separating the enumeration values from their display tokens, allowing you to change one without changing the other. The disadvantage is that they can become unsynchronized...
|
|
|
|
|
Yet another possibility:
public enum ByteEnum
{
FortyNine = (byte)'1',
Fifty = (byte)'2',
FiftyOne = (byte)'3'
}
I keep thinking you want something other than an Enum here (a Struct ?), but I am not quite sure what that "other" might be.
«I'm asked why doesn't C# implement feature X all the time. The answer's always the same: because no one ever designed, specified, implemented, tested, documented, shipped that feature. All six of those things are necessary to make a feature happen. They all cost huge amounts of time, effort and money.» Eric Lippert, Microsoft, 2009
|
|
|
|
|
byte[] result = Encoding.ASCII.GetBytes(PackageType.STANDARD.ToString());
|
|
|
|
|
Is it possible to design a program that will launch explorer, wait until a dialog box appears in explorer and then activate a button in the dialog box. Wait until another dialog box appears and then automatically complete the username and password in That dialog box and finally terminate the program?
An analogy would be Explorer automatically connecting to one's banks website that does not allow saving username and passwords.
This is a program I am trying to develop for visually impaired people for easy login access to the local library. When you launch explorer in the library it automatically tries to connect to the library's website.
All constructive comments are welcome.
|
|
|
|
|
Depends where the login is. If it is on the desktop, then yes, you can get a handle to the process and all controls it creates, and manipulate them by sending messages. If it is in the login-screen, then no.
picardy wrote: This is a program I am trying to develop for visually impaired people for easy login access to the local library. Yup, but you are suggesting that the locked door opens automatically for them. In that case, it'd be easier to simply remove the lock completely.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
When one opens explorer in the library, it attempts to connect to the library wi-fi network. The dialog boxes are inside the explorer window. I cannot remove or change any library security measures. I was wondering if I had a handle to that instance of explorer if it would be possible to loop for all objects inside explorer's window and if that object was of type 'button' and label contains 'Accept' if I could select that button. Similarly, for the next dialog window.
|
|
|
|