|
You'll pretty much have to read with timeout.
What sort of brilliant designer doesn't allow a 'wait and see if any data comes in, but recognize that a lack of data is also a normal condition' operation? Probably the same one who designed .net 1.0 without things like Date.TryParse I guess.
I wish there were some sensible way of enabling the diagnostic messages for exceptions in some cases but not all. In some of my applications there are exceptions which will be somewhat expected though they shouldn't be terribly frequent. In such cases, I sometimes just swallow them (assuming they're of the right type) but the "First chance exception" diagnostics can alert me if they're happening much more often than they should. Is it possible to hook in some sort of event handler for a first-chance exception that could log exceptions that seem suitable (using a thread-safe logging system, of course)?
|
|
|
|
|
supercat9 wrote: Probably the same one who designed .net 1.0 without things like Date.TryParse I guess.
Okay - I feel that is an unfair comment. I attended a talk last year at Microsoft and what was interesting was that they were saying that there were aspects to C# and the .NET framework that have been on the drawing board since before V1 was released that are only just going into V4.
Now, think about this from a business perspective. Do you wait until you have an absolutely perfect product before going to market, or do you go to market earlier with a product that will satisfy most people? If you answer the former then you won't last very long in business because you'd burn through your Venture Capital way before you released anything to the market and your competitors would have stollen all your potential customers.
Seriously, ignorant comments like that really piss me off. Yes, the .NET Framework may have its faults but are you seriously telling me that you've never had to cut features or use a workaround because of business and time-to-market pressures?
|
|
|
|
|
I did finally figure out a way to make the serial port work reasonably, using a received-data event to hit a ManualResetEvent (if the main communication thread has set it). The code creates a new ManualResetEvent every time the main thread polls and there isn't any data available; a monitor might be better, but using the ManaulResetEvent makes it possible for another thread to set a 'hurry up and abort the current operation' WaitHandle (which could be used, along with the former, in a WaitAny).
Okay - I feel that is an unfair comment.
Since there seems to be a good solution using events, I'd agree that my apparent antipathy toward the authors of the SerialPort class was somewhat misplaced. The Windows communications API has somewhat dubious semantics (which probably go back aeons) and the SerialPort class is mostly just exposing them. The decision to have a timeout error always throw an exception is unfortunate, but the availability of the receive data event makes it possible to emulate the two styles of semantics that a good communications library should support:
-1- Wait up to a specified time for 'n' bytes; if fewer than 'n' bytes become available in time, do not return a smaller number, but instead flag an error (or throw an exception).
-2- If any data is available, return it. Otherwise, wait up to a specified amount of time (possibly zero) to see if any arrives.
The Windows API is a mishmosh of these approaches, so I suppose it makes sense that the SerialPort class would be as well.
Colin Angus Mackay wrote: Do you wait until you have an absolutely perfect product before going to market, or do you go to market earlier with a product that will satisfy most people?
Maybe I was a bit too sarcastic, but to my mind the concept of a 'try' pattern should be a core part of any non-trivial exception-based code, except in circumstances where it's not practical to predict an operation's success without committing to the operation. Whoever made the first-chance exceptions go to the immediate window was clearly trying to encourage programmers to avoid exceptions when practical; a worthy goal, but one which requires giving programmers the tools to do that.
I guess what I find most irksome/puzzling about things like Date.Parse is that I can't imagine that people could use such a function very much without its limitations quickly becoming apparent. If Microsoft had to code around the limitations of something like Date.Parse in order to make its other products work, that would suggest that such workarounds should perhaps have been included in the .net framework in the first place.
Yes, there's a lot more to Windows and .net than meets the eye, but I doubt I'm the only person to stumble upon some of the annoyances.
modified on Thursday, January 8, 2009 10:28 PM
|
|
|
|
|
HI All,
I wrote the following code and i checked with task manager.the result is not correct .Can anyone help me ?
public string Checkcpu()
{ double cpuPercent=0;
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name=\"_Total\"");
foreach (ManagementObject objMgmt in searcher.Get())
{
cpuPercent = Convert.ToDouble(objMgmt["PercentProcessorTime"]);
//cpuPercent = objMgmt["_Total"].ToString();//not found
}
//return cpuPercent.ToString();
return _format ? (int)cpuPercent + "%" : cpuPercent.ToString("F") + "%";
}
|
|
|
|
|
S.Rekka wrote: the result is not correct
How so?
Are you calling this at intervals?
This works for me:
for (int i = 0; i < 100; i++)
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT PercentProcessorTime FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name='_Total'");
foreach (ManagementObject objMgmt in searcher.Get())
{
Console.WriteLine("PercentProcessorTime: {0}%", objMgmt["PercentProcessorTime"].ToString());
}
Thread.Sleep(100);
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
yes,i called that function in timer tick.but the wmi result shows on 12% means that task manager shows 34% .I used PerformanceCounter method also it shows on correct. But wmi shows on wrong result.I want to get on wmi only.
|
|
|
|
|
Hiiiiiiiiii all experts........
this is ajay pandey and i m working on a project which requires calling an exe from the init() method.can any body tell me how to implement this and other features of a server which requires processing the data from user b4 it is passed to service method to b served.
Plz suggest me any book if u have in mind as i m a beginer,...........
Thanks
|
|
|
|
|
I think you want to execute an exe in init() mathod?
You can add the namespace System.Diagnostics and can use the Prcess class to execute the exe as
Process myprocess = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo("path of you exe");
myprocess.StartInfo = startInfo;
myprocess.Start();
The process would be started and check when this process would be exited then start executing ahead.You can use timer for it.
Cheers!!
Brij
|
|
|
|
|
Hi,
I have a project that is being with SCSF. The project is in first days & we are developing the base classes such as Bussines Entities, ... .
In this process, when I want to run project from Visual Studio, I got Exception with this message :
-------------------------------------------------------------------------------------------------------------------
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Infrastructure.Library.Properties.Resources.resources" was correctly embedded or linked into assembly "Infrastructure.Library" at compile time, or that all the satellite assemblies required are loadable and fully signed.
This exception has occur in the following code:
if (traceSource != null)
traceSource.TraceInformation(Properties.Resources.LogModuleAssemblyLoaded, file.FullName);
-------------------------------------------------------------------------------------------------------------------
This is when until yesterday I could run the project & see output.
Please help me ...... thanks
modified on Thursday, January 8, 2009 4:35 AM
|
|
|
|
|
|
I am developing a mailing application in .Net 2005 (windows). Application requires sending a mail to recipients. The body of the mail can also have emoticons.
For writing the body of the mail and inserting emoticons, Rich text box is provided. All emoticons are available on my local system. Emoticons show up when the mail is written and emoticons inserted, but when the mail is sent, emoticons don't show up on recipient's machine.
Can Alternate views and Linked Resources be used to insert emoticons dynamically or is there any other way to do this.
Thanks in advance
|
|
|
|
|
Vivek Bhatnagar wrote: All emoticons are available on my local system...emoticons don't show up on recipient's machine
Should be clue here don't you think? You will have to embed the images or link them to an external resource that is available to the recipient
only two letters away from being an asset
|
|
|
|
|
Wouldn't the email also have to be HTML for images to show?
Otherwise wouldn't they just be an attachment?
|
|
|
|
|
Sorry, that was a given, didn't think I needed to mention the obvious
only two letters away from being an asset
|
|
|
|
|
from the OP I didn't know if he knew that, assuming he used a RTB I think he may have forgot that, which is why I was asking...
|
|
|
|
|
Suppose your site is abc.com.
Now in your mail the path for the emoticons should be
http://www.abc.com/images/a.jpg
not images/a.jpg
Try using it, i think it will solve your problem
|
|
|
|
|
I think the images are on his PC, not on a web-connected server
|
|
|
|
|
Its a Windows application using System.Net.Mail class. The application won't be available on net.
In the application, the user writes a mail and can paste\insert few images\emoticons (present on local machine) in a RTB provided.The contents of RTB are then assigned to 'Body' property of MailMessage class and then the mail is delivered to recipients.The pictures are not showing up on recepient's machine
|
|
|
|
|
You need to host images online, otherwise you cannot display the images in mail
|
|
|
|
|
Thanks for all your responses.
All the images are located on my local system. Whenever a user selects an emoticon to be inserted, I am using the following code:-
Clipboard.Clear()
Clipboard.SetImage(strPicture)
Dim PictureFormat As DataFormats.Format = DataFormats.GetFormatDataFormats.Bitmap)
rtbContents.Paste(PictureFormat)
The contents of RTB (which includes text as well as emoticons) is assigned to 'Body' property of MailMessage class. Also 'IsBodyHTML' is set to true. Now when the mail is sent, the emoticons instead of appearing at the place where they were inserted, they are appearing as an attachment.Any suggestions?
|
|
|
|
|
Yes, attach the images as an attachment and format your body using HTML, You cannot do it the way you are describing.
|
|
|
|
|
Images can be inserted to the mail body by embedding them as linked resources.We need to first create an alternate view
Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString(rtbContents.Text, Nothing, "text/html")
Next all images inserted to the mail body are embedded as linked resources to AlternateView with each image having a unique id.Next the alternate view is added to the MaiMessage object.
Once again thanx for all your responses
|
|
|
|
|
Hi, I am trying to create a function in vb .NET that can calculate the travel time from one point (P(x,y)) to another point(Q(x,y)) knowing the speed as a constant per squere. Exemple 1 square = 00:12:00.
When I calculate the distance between the 2 points, the result is a double, for example 4.32.
To get the travel time I need to multiply 4.32 by 00:12:00 (double, by datetime).
I have tried using Convert.ToDouble method and TimeSpan but i didn't manage to work with them.
How can this be achieved?
The end result should be in datetime format.
|
|
|
|
|
Hi,
a travel time is a TimeSpan, not a DateTime. (what would be the meaning of 08-JAN-2009 times two?)
The TimeSpan type offers Add methods but no Multiply methods, however it has a Ticks getter property so you can convert it to ticks, and it also has a constructor(ticks) so you can create a new TimeSpan with a new value.
modified on Wednesday, January 7, 2009 11:27 PM
|
|
|
|
|
Hi, thanks for the reply ...
I have converted the time in seconds (integer). This has helped me to multiply the time(s).
Then using the DateAdd(DateInterval.Second,seconds, date start) to calculate if you start from a date, from a point, when you will reach the next one, if you know the travel time in seconds.
Now it is clear for me...
|
|
|
|