|
In my experience, using BeginReceive etc does not cost you any throughput (at reasonable speeds) - but that's all I know, I don't do much socket programming
|
|
|
|
|
Thabks harold.
Your help is appreciated.
"I hope you live a life you're proud of. If you find that you're not, I hope you have the strength to start all over again." - I wish I knew who is this quote from
|
|
|
|
|
When you use your own threads, you are in charge. You can do whatever pleases you; the price for that is the expense of a thread. Each thread needs its own context, consisting mainly of a stack, which by default takes 1MB of memory.
When you use asynchronous operation, you are relying on how they implemented that. .NET asynchronous operations use ThreadPool threads, which is a pool of threads with certain characteristics. The big advantage in using ThreadPool is you can get the same activity covered with fewer actual threads, which is great especially when you would need hundreds or thousands of them, e.g. because you have that number of sockets, or timers, or serial ports.
There are disadvantages too, of course. You can't change most of the ThreadPool characteristics, e.g. stack size, thread priority, etc. And you can't change the dynamic behavior of the ThreadPool; it will start with only a few active threads, and the way they implemented it, it will detect heavy load and add more threads at a fixed rate of only 2 per second. There are some parameters one can set, but they are few because the ThreadPool is used by .NET itself, hence it needs to get launched long before your first line of managed code executes.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Thank you so much. Detailed and informative.
For what I'm doing right now, using saync functions seems to be good enough.
Truth is that we don't want connections for the sake of just connections. So after connections established and when data transfer starts there will be threads and all those context switching stuff. If the only benefit is that it uses thread pool, I think we can use it if we needed. Although they probably have better performance in their thread pool. They most probably use WinSock async APIs and those native calls must be very fast.
Your answer helped me a lot.
Thank you again.
"I hope you live a life you're proud of. If you find that you're not, I hope you have the strength to start all over again." - I wish I knew who is this quote from
|
|
|
|
|
you're welcome.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hi, I was just trying to figure out how to get the C# platform to give me standard Unix Time (ie the number in seconds since 12:00 AM January 1, 1970), which is pretty universal (i thought) throughout programming. If anyone knows how to get this time it would be very useful. Thanks,
|
|
|
|
|
jojoba2011 wrote: which is pretty universal (i thought)
Not since ISO 8601 came out.
Quick-and-dirty extension methods to do that:
namespace PIEBALD.Lib.LibExt.UnixTime
{
/**
<summary>
Library of extension methods that convert to and from UnixTime
</summary>
*/
public static partial class LibExt
{
private static readonly System.DateTime Epoch ;
static LibExt
(
)
{
Epoch = new System.DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 ) ;
return ;
}
public static int
ToUnixTime
(
this System.DateTime Time
)
{
return ( (int) ( Time - Epoch ).TotalSeconds ) ;
}
public static System.DateTime
FromUnixTime
(
this int UnixTime
)
{
return ( Epoch.AddSeconds ( UnixTime ) ) ;
}
}
}
|
|
|
|
|
See if this[^] helps you.
Kristian Sixhoej
I have noticed even people who claim everything is predestined,
and that we can do nothing to change it, look before they cross the road. - Stephen Hawking
|
|
|
|
|
Plz help
these codes doest help me out.
Please give me correct Example.
Thanks for reply
|
|
|
|
|
What is the problem? The following code, which I found on the site I posted in my message above works just fine for me.
public static long GetEpochTime()
{
DateTime dtCurTime = DateTime.Now;
DateTime dtEpochStartTime = Convert.ToDateTime("1/1/1970 12:00:00 AM");
TimeSpan ts = dtCurTime.Subtract(dtEpochStartTime);
long epochtime;
epochtime = ((((((ts.Days * 24) + ts.Hours) * 60) + ts.Minutes) * 60) + ts.Seconds);
return epochtime;
}
To use it:
Console.WriteLine("Number of seconds since 1/1/1970 @ 12:00:00 AM: " + GetEpochTime());
Kristian Sixhoej
I have noticed even people who claim everything is predestined,
and that we can do nothing to change it, look before they cross the road. - Stephen Hawking
|
|
|
|
|
That'll work on English systems only (or systems set to accept dates in English format).
The string format of dates is culture-specific, so Convert.ToDateTime will fail with that hard-coded date on non-English systems.
Use DateTime.Parse("1/1/1970 12:00:00 AM", CultureInfo.GetCultureInfo("en-US")) , or simply new DateTime(1970, 1, 1) .
Edit: Oh, and the site you linked to used UtcNow , you're using Now . Unix dates are the seconds since 1st January 1970 GMT, so your code produces incorrect results almost everywhere in the world (even in the UK, it's only correct during winter time).
|
|
|
|
|
Describe the problem you're having.
|
|
|
|
|
Hello,
I want to insert for example the next data into a string variable:
string temp="abc"efg";
How can i do it? there is an error because of the " char . (new line in constant error)
|
|
|
|
|
Just put a \ behind " like this:
string temp="abc\"efg";
"I hope you live a life you're proud of. If you find that you're not, I hope you have the strength to start all over again." - I wish I knew who is this quote from
|
|
|
|
|
Apart from the first solution, you can also try
string temp=@"abc""efg";
My signature "sucks" today
|
|
|
|
|
It should be
string temp=@"abc"efg";
|
|
|
|
|
Give it a try - it won't compile.
My signature "sucks" today
|
|
|
|
|
|
Hi I'm new to OOP so having lots of trouble trying to do simple things. I have an Excel file that has data in one of its sheets and I want to to copy 2 (or more) columns and 400 rows of that data into an Array which will reside in a C Sharp programme.
I've built individual Arrays for the 2 columns and have also managed to read the Excel file but I can't seem to get them to populate my Array. I can read Text files as well but I can't seem to able to put them in an Array especially if its multidimensional and has not string and double
any thoughts would be much appreciated.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
public static void Main()
{
string [] Pat = new string[400];
double[] Data = new double[400];
//int contents = 0;
string[] range = new string[6];
Excel._Application app = new Excel.Application();
Excel.Workbook small1 = app.Workbooks.Open(@"C:\Users\Worc\Desktop\small.xls");
Excel.Worksheet sheet1 = Excel.Worksheets.Equals(small1.Worksheets[1]);
Excel.Range r = sheet1.Columns;
Excel.Range r = sheet1.get_Range("B2:B400");
//for(int i = 0; i < sheet1.Range; i++)
//{
//
//}
Console.WriteLine("Value, {r}" , r);
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hi
|
|
|
|
|
I would start with the button2_click code from
http://support.microsoft.com/kb/302096[^]
but replace
valueString = String.Concat(valueString,
saRet[rowCounter, colCounter].ToString() + ", ");
with something like
s[rowCounter, colCounter] = colCounter].ToString();
where s is defined as
string[,] s = new string[xx,yy];
obviously you'll have to pick some values large enough for xx and yy - since you can get the size eof the array in iRows, iCols, you can use those values to dynamically allocate a large enough array
|
|
|
|
|
Try something like:
int index = 0;
foreach (Excel.Range rc in r.Cells)
{
array[index] = rc.Cells.Value;
index++;
}
[edit]
There's probably a more straightforward version of this (like Garth's suggestion) but I'm sure you get the idea.
[/edit]
It's time for a new signature.
|
|
|
|
|
Hi.........
Please help me to solve my problem.
I have developed one software in VS2008. It is being installed at client site. The problem I encounter is regarding crystal Report in that project.
All my reports are working properly except one. This One is running properly on Windows7 but not on Windows XP. It gives an error as "Unhandled Exception Occured At Your System." at Runtime. While Debugging it on Windows XP it Shows Error as "Invalid Table Number."
Thanks And Regards
Sanket.Patil
.
|
|
|
|
|
See here or here.
My signature "sucks" today
|
|
|
|
|
Hi Abhinav,
Thanks for the reply.
But The Problem is My Report Works Properly on Windows7 and not on Windows XP. I ahve only one database attached to my machine and copy of this database is also attached to another machine. This means database is same data is also same only when i change OS windows7 to Windows XP Report Throws an exception.
thanks and regards
Sanket.Patil
.
|
|
|
|
|
Try and search for this error on the internet. A lot of posts discuss this error and many of the reasons mentioned are different - so you might find a solution somewhere.
My signature "sucks" today
|
|
|
|