|
there is no ordering of threads, when they are "ready", i.e. have some work to perform and not waiting on something, then the operating system can pick any N of them (for N cores), assuming all have the same priority. If you want to order them, you need synchronization, which probably annihilates the advantages of having multiple threads anyway.
it does not make sense to me to use multiple threads for sending messages that have to have a specific order; you might have more than one thread coming up with messages (and storing them somehow), but when order is important, you'd better have only one sender thread. And probably manufacturing the messages isn't worth the trouble of multiple threads either, so I suggest you keep it simple.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Octantis wrote: I'm working on tracking the threads to verify my claim.
No need to verify anything.
Threads do not run in "order" unless you add something explicitly that forces them into some order (causes them to block or otherwise limits how they run.)
|
|
|
|
|
The answer as expected did point to the sender and his using of a throw away thread to send a single message. Now instead I drop those messages into a queue and then send them off within its own separate thread. Problem solved.
You guys did bring up the question of unsafe read practices. Specifically when things would get out of sync. I understand what you mean by an errant byte being assumed as a string or a size. In general how do you guys handle that? Put in super unique character strings like #$$# with the next following character being the size and then seeking the buffer looking for those values? The TCP layer should ensure that the data shows up (eventually) unmolested. So something like that would only serve to hide errors in the sending code and not something outside your realm of control.
I'll mark this problem as solved. Once again thanks for the help.
|
|
|
|
|
Presumably you mean sending via TCP.
I don't send data - I send messages.
Data is what I want delivered. A message is the envelope which contains the data. At a minimum it contains a value that indicates the size of the data. So the message contains the size and then the data.
Sometimes I put other things in there like data type identifiers.
|
|
|
|
|
Hello,
I have a pdf file with the arabic name. and i want to view in adobe pdf reader.
if the file name in english then PDF file view successfully.
but when i load the arabic filename then its dosent view.
So please suggest me, how to view arabic file name PDF.
Thanks
Raushan Kumar
|
|
|
|
|
What C# code have you got so far? If you post it we can take a look at it and make suggestions on how to fix it.
|
|
|
|
|
Hello,
This may be more of a PowerPoint issue that a C# one, but I thought I would try it this way since I cannot find a PowerPoint solution for this. I have written a C# application that calls PowerPoint slides from a menu. I would like to know if there is a way to randomly change the background of each PowerPoint slide that is called by selecting the graphic from a list of possibles. I cannot find a way to do this in PowerPoint alone and I wondered if there was a way to have C# do it for me; or perhaps if there is another solution? Thanks for your thoughts....Best, Pat
|
|
|
|
|
You are right. This is nothing at all to do with C#. I would suggest that a possible solution would be to use VBA to randomly choose the background and apply it.
|
|
|
|
|
Ok Pete....just did not know where to turn on this one so I took a shot. The good news is that your suggestion worked; I was able to modify some VBA code I found and make it work along the following lines (even though I have never written a word in VB before):
Public Sub ChangeBackgrounds()
'Global array to store pic names
Dim PictureList(1 To 10) As String
'List of pictures - in same directory as ppt:
PictureList(1) = "pic1.JPG"
PictureList(2) = "pic2.JPG"
PictureList(3) = "pic3.JPG"
PictureList(4) = "pic4.JPG"
PictureList(5) = "pic5.JPG"
PictureList(6) = "pic6.JPG"
PictureList(7) = "pic7.JPG"
PictureList(8) = "pic8.JPG"
PictureList(9) = "pic9.JPG"
PictureList(10) = "pic10.JPG"
'Define a slide
Dim mySlide As Slide
'Iterate through every slide in the presentation
For Each mySlide In ActivePresentation.Slides.Range
Dim PictureChoice
'Give us a random number between 1 and 10 as PictureChoice
PictureChoice = Int((20 * Rnd) + 1)
' Don't follow the master background style
mySlide.FollowMasterBackground = msoFalse
mySlide.Background.Fill.UserPicture (PictureList(PictureChoice)) 'Use our random number to choose a picture from the list
Next mySlide
End Sub
Thanks...Pat
|
|
|
|
|
good advice!
Craigslist Troll: litaly@comcast.net
"I have a theory that the truth is never told during the nine-to-five hours. "
— Hunter S. Thompson
|
|
|
|
|
Hi
I am having trouble building my database connection string, i have to read the server name, db, un, and password from an INI file (dont ask)
This is no problem, but im having trouble using these values to build my connection string
currently im getting the error
A field initializer cannont reference the nonstatic field, method or property
my knowledge of C# is basic to say the least, can anyone point me in the correct diretion or help at all?
thanks
Simon
Code Below
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using System.Net;
using System.Xml;
using System.Runtime.InteropServices;
namespace WebService1
{
public class Service1 : System.Web.Services.WebService
{
string con;
string ini_path;
string tc_server="";
string tc_database="";
string tc_un="";
string tc_pwd="";
string tc_server_str="";
public Service1()
{
InitializeComponent();
ReadIniSettings();
con=CreateConnectionString();
}
SqlConnection myConnectionCP2 = new SqlConnection(con);
#region Component Designer generated code
private IContainer components = null;
private void InitializeComponent()
{
}
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
void ReadIniSettings()
{
ini_path="F:\\Web\\tr\\htdocs\\cpbl4\\";
tc_server = IniFile.ReadValue(ini_path,"TC","Server");
tc_database=IniFile.ReadValue(ini_path,"TC","Database");
tc_un=IniFile.ReadValue(ini_path,"TC","UN");
tc_pwd=IniFile.ReadValue(ini_path,"TC","Pwd");
}
string CreateConnectionString()
{
tc_server_str=SQLConn.CreateConnStr(tc_server,tc_un,tc_pwd,tc_database);
return tc_server_str;
}
}
public class IniFile
{
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section,string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section,string key, string def, StringBuilder retVal,int size, string filePath);
public static void WriteValue(string path, string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, path);
}
public static string ReadValue(string path, string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp, 255, path);
return temp.ToString();
}
}
public class SQLConn
{
public static string CreateConnStr(string server, string un, string pwd, string db)
{
string connStr = "server="+server+";max pool size = 7500;uid="+un+";pwd="+pwd+";database="+db+";Connect Timeout=200;";
return connStr;
}
}
}
|
|
|
|
|
Probably this line: SqlConnection myConnectionCP2 = new SqlConnection(con);
You're trying to create the SQL connection in a field initializer... Not a good thing. That should be initialized inside the constructor (Or inside another function).
|
|
|
|
|
This is the offending line:
SqlConnection myConnectionCP2 = new SqlConnection(con); Basically, you are using the value of one field while attempting to initialise another outside a method. This is not allowed - after all, what value is it? What you need to do is create the SqlConnection object, and then initialise it inside a method (although, in your example, you aren't using it anywhere).
|
|
|
|
|
The error is being generated on this line;
si_69 wrote:
which appears at present after the block shown below, with a bit of jiggery pokery, move the object declaration and the initilisation so you end up with the code refactored to;
SqlConnection myConnectionCP2;
public Service1()
{
InitializeComponent();
ReadIniSettings();
con=CreateConnectionString();
myConnectionCP2 = new SqlConnection(con);
}
That should hopefully fix the problem
|
|
|
|
|
compilers usually produce messages including filenames and line numbers. Use them to your advantage, and make sure your IDE always shows line numbers in source editor windows. For Visual Studio, check menu Tools/Options/Text Editor/All Languages/General: "Display Line Numbers".
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Let's not forget that double clicking the error should take you to the exact line.
|
|
|
|
|
When using VS and all happens to be well, which could be a stretch.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
guys;
I was exminning some code and i found this:
try
{
try
{
...
}
finally
{
...
}
}
catch
{
throw;
}
I am wondering if this is legal. I mean catch anything and trow anything;
or maybe it's usefull for something. because the developer who write this code is someone i believe he is an expert.
Thank you;
Help people,so poeple can help you.
|
|
|
|
|
Guy ( or girl .. dunno )
A try is always followed by a catch section, hence the name try.catch block.
The sample you provided is legal, however I would add an additional catch block in case anything goes wrong in the second try section.
try
{
try
{
...
}
catch
{
}
finally
{
...
}
}
catch
{
throw;
}
|
|
|
|
|
Rick van Woudenberg wrote: A try is always followed by a catch section, hence the name try.catch block.
Incorrect. A try-finally construct is perfectly legal. It is only when a try block is followed by a catch block that they are called a try-catch construct.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
.. euhmm .. debatable I guess. Technically speaking you're right, I agree. But what's the use of a try block without a catch block. The try block contains the guarded code that may cause the exception. The block is executed until an exception is thrown or it is completed successfully. The catch clause can be used without arguments, in which case it catches any type of exception, and referred to as the general catch clause. It can also take an object argument derived from System.Exception, in which case it handles a specific exception. So, keeping all that in mind, I'm hard to convince why you'd want two or more try clauses with just one catch clause, as each try block is examined in order of importance and thus handled by the same catch clause.
.. or have I completely lost my mind again.
|
|
|
|
|
Rick van Woudenberg wrote: But what's the use of a try block without a catch block.
To ensure that the exception gets thrown up the chain, AND some critical piece of code gets executed. Consider this example:
private void DoSomething()
{
SqlConnection connection = null;
try
{
connection = new SqlConnection();
}
finally
{
if (connection.ConnectionState == ConnectionState.Open)
connection.Close();
}
} BTW, try/finally is exactly how the using statement is implemented for auto-disposable behaviour.
|
|
|
|
|
Pete,
Good point. I guess you're sample is way better than I used to do it. ( see code below ). Other than the obvious thread freezing and just the fact that handling exceptions are 'expensive'.
private void DoSomething()
{
SqlConnection connection = null;
try
{
connection = new SqlConnection();
connection.Open();
}
catch
{
MessageBox.Show("Connecting to the database failed..");
}
if (connection.ConnectionState == ConnectionState.Open)
connection.Close();
}
|
|
|
|
|
That code example made me shudder.
Separation of concerns; Is the concern database access or User notification, because it sure as hell shouldnt be both.
|
|
|
|
|
Well, as far as I'm concerned both would be nice. Sure, the connection to the database has priority over user notification, however when something stuffs up, I generally let the user know. In that particular case I would do something like :
private void DoSomething()
{
SqlConnection connection = null;
try
{
connection = new SqlConnection();
connection.Open();
}
catch(SqlException ex)
{
MessageBox.Show(ex.ToString();
}
finally
{
if (connection.ConnectionState == ConnectionState.Open)
connection.Close();
}
}
Then you actually have both of two worlds. However, that puts us right back to the essence of this discussion. Having a catch clause in a method is not something to be ashamed of, though I get the feeling that many developers think that way.
|
|
|
|