|
Is there any way to tell the system that a certain exception is sufficiently "expected" that I don't want it to be reported in the debug/immediate window? I know that ideally code would avoid causing exceptions in the first place, but that isn't always possible. For example, if I want to write a 'terminal' program that can operate using either a serial port or a socket, I need to find out if there's any data available to be read; the only way I know to do that is to try the read and see if it works. If it doesn't, it will throw a system.TimeOutException. Reporting that zero bytes were received when that happens works, but the debug/immediate window gets so flooded with first-chance exception messages as to be otherwise useless.
If I wanted to code the reader to explicitly expect certain types of streams (e.g. TCP socket or serial port) I could explicitly use the data-ready functions for those, but that would defeat the purpose of object-oriented programming.
|
|
|
|
|
Maybe I am not understanding you 100%, but it sounds like you are looking for a try-catch block:
<br />
Try<br />
<br />
Catch ex As Exception<br />
<br />
End Try<br />
Pete Soheil
DigiOz Multimedia
http://www.digioz.com
|
|
|
|
|
I have a try-catch block:
Try
n = stream.Read(b, 0, 1024)
If n Then
Broadcast(2, b, n)
End If
Catch ex As TimeoutException
n = 0
End Try
The code works, but my debug/immediate window is flooded with thousands of
A first chance exception of type 'System.TimeoutException' occurred in System.dll
Makes the debug/immediate window useless for anything else.
|
|
|
|
|
Have a look at the menu Debug/Exceptions...
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
The Debug/Exceptions menu lets one specify whether exceptions should cause a program to stop in the debugger, and whether such behavior should occur even when a user exception handler exists. I don't see anything in there to control the diagnostic messages, though. They print even if the timeout exception is disabled in the Debug/Exceptions menu.
|
|
|
|
|
Well that's too bad. I am using C# and have some timeouts in my code, mainly for dealing
with exceptional cases tho. Can't you cut it with the Socket.Available property
and the SerialPort.BytesToRead property or the SerialPort.DataReceived event?
Seems to me you could read the property, and if insufficient data is present, do
Thread.Sleep(delay), then read the property again. (For bigger delays you might choose
to do more property reading).
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
I finally decided that since my goal is (as noted in a different reply) to simply get something that works, I'll put up with the ugliness of explicitly checking within my polling handler to see what sort of stream I'm dealing with and handle the different types explicitly. I don't like doing that, and it somewhat defeats the purpose of object-oriented programming, but given that the program is for test purposes anyway, it's better to get the thing done quick-and-dirty than spend too long worrying about how to do it cleanly.
|
|
|
|
|
Hi,
you could define an interface with a DataAvailable property and a Read method,
then encapsulate each of your data sources in a class that implements that interface, and
finally have your data consumer simply call the interface members; doing so would
keep the consumer unaware of the uglyness of (some) data sources, as OO would require.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
There's no way to suppress those messages. It sounds like your code is generating, and relying on, those thousands of exceptions. I would probably reconsider the design of whatever is generating all these exceptions.
For example, if your design is relying on polling (like your code example suggests), you may want to scrap it and rewrite it in an asynch setup.
|
|
|
|
|
Certainly polling is less than ideal in many production situations, since it can lead to excessive CPU utilization. On the other hand, it can also provide a quick and easy way to make things work, especially in test environments (I'm working on a DSP system, and just trying to write PC-side software to monitor and debug the DSP). I've already spent more time trying to learn VB.Net than I would have liked; though such knowledge will certainly be useful in future, it doesn't help my DSP project which is already behind where I want it to be.
|
|
|
|
|
I am working on a project that pulls SQL Server data and places it into a MS Access database. The dataset contains 3438 rows, and 0 rows are inserted into Access. There are no errors when the code run, just nothing happens. The code is listed below:
Public Function InsertAccessData(ByVal dsTDO_Header as dataset) As String
Dim cn As New OleDbConnection(strACCDBConn)
Dim strSQL As String = ""
Dim DA As New OleDbDataAdapter
strSQL = "Select * from TDO_HEADER"
DA.SelectCommand = New OleDbCommand(strSQL, cn)
DA.FillSchema(dsTDO_Header, SchemaType.Source, "TDO_Header")
Dim oleCB As New OleDbCommandBuilder(DA)
Try
cn.Open()
oleCB.GetInsertCommand()
DA.Update(dsTDO_Header, "TDO_Header")
''dsTDO_Header contains 3438 records,
''DA.Update inserts 0 Records in db with no errors
''that is the problem
cn.Close()
cn.Dispose()
DA.Dispose()
Catch ex As Exception
Dim strErrMess As String
strErrMess = "Something didn't work right we received this update error: " & ex.Message
cn.Close()
cn.Dispose()
DA.Dispose()
Return strErrMess
Exit Function
End Try
Return "Success"
End Function
Can anyone see where I went astray?
Thanks in advance for any help.
culbysl
|
|
|
|
|
First, this is a bad way to do this.
Second, the DataAdapter is looking at the status of each row in each table in your source dataset that you pass in and not seeing rows that are tagged changed, added, or deleted. So, yes, the DA is doing nothing, because it hasn't found anything to do! It doesn't know that these rows need to be added to the Access database, because it doesn't know anything about the Access database. It's looking solely at the rows you passed in the dataset.
I would recommend reading up on the documentation for any of the DataAdapters to understand HOW and WHY they work the way they do.
|
|
|
|
|
Thanks for getting back to me. I'm get started learning more about dataadapters. As for your first statement, could you recommend another way of doing this?
Thanks again
|
|
|
|
|
Try using the insert command instead update... you need to creat the some odd thousands of records not update 0
|
|
|
|
|
Hello,
I have a question that...the more i try and research online the more confused I get.
What is the difference between typed and untyped datasets.
What I understand is that typed datasets inherit schema information and untyped dont. It seems like there has to be more to it then that.
Erica
|
|
|
|
|
|
I want to make a 'wall' (picturebox) that the cursor cannot pass through.
This snippet that does NOT work. This is about all i got so far. Mouseposition is a read only so this code can't work.
If Me.MousePosition.X > Me.rightwall.Left Then
Me.MousePosition.X = Me.rightwall
End If
|
|
|
|
|
Me.MousePosition is a Point, and Points are immutable, you can't change them, but you
can replace them by a new Point.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hey guys,
I am trying to create a simple program that will graph a polynomial function.
I have followed a tutorial at about.com, and I ran into a problem while programming. Here is the program so far. I left out the designer generated code. There are two textboxes where the user inputs coefficients for the polynomial, a button that the user presses to draw the graph, and a panel where the graph is drawn. I get an error underlining the New Point under the Button1 Click event that says:
Value of type System.Drawing.Point cannot be converted to System.Drawing.PointF
===========================================================================
Imports System.Drawing.Drawing2D
Imports System.Math
Public Class Form5
Inherits System.Windows.Forms.Form
Dim PolyPoints(100) As PointF
Dim Counter As Integer
Dim P As Pen = New Pen(Color.Crimson, 3)
Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
e.Graphics.DrawCurve(P, PolyPoints)
MyBase.OnPaint(e)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim G As Integer
Dim H As Integer
G = TextBox1.Text
H = TextBox1.Text
For Counter = 0 To 99
PolyPoints(Counter) = New Point(Counter, G * ((Counter) ^ 2) + H * ((Counter) ^ 3))
Next
Panel1.Refresh()
End Sub
End Class
============================================================================
I am a novice programmer, and this seems to be a very simple problem. Thanks for your help in advance
Sincerely,
B.T.
|
|
|
|
|
Hi Billy,
you declared PolyPoints as an array of PointF objects (not sure why tho),
so you should only try to move PointF objects in there.
Why not use new PointF(...) ?
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
I declared it as an array so that I could have a series of a hundred points connected by the DrawCurve. Is there an easier way to do this?
When I replace new Point(...) with new PointF(...), I get a similar problem message.
Value of type 'System.Drawing.PointF' cannot be converted into '1-dimensional array of System.Drawing.PointF'.
I'm not sure what dimension why PointF isn't considered 1-dimensional. Please advise.
Thanks for replying Luc.
B.T.
|
|
|
|
|
Hi Billy,
1.
this does not make sense; the error message "Value of type 'System.Drawing.PointF' cannot be converted into '1-dimensional array ..."
would fit the statement PolyPoints = New PointF(Counter, G * ((Counter) ^ 2) + H * ((Counter) ^ 3))
but yours has/had the index (Counter)
2.
there is another error too, you can't take a textbox text and store it in an integer like
that. You would need something like G = Convert.ToInt32(TextBox1.Text) .
3.
Furthermore if an invalid number is entered (empty, letters, whatever), the code would
throw an error; either provide a try catch construct, or use Int.TryParse or so.
4.
I reckon you want two distinct textboxes for G and H?
5.
You probably want to use floating-point numbers for G and H (and Float.TryParse),
otherwise there is no sense in using PointF and your graphics will not fit your panel...
-- typo corrected at 20:04 Monday 19th November, 2007
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hi Everyone:
I'm trying to teach myself VB 2005 .NET and the best way I have found to learn something is to make a project in the language I wish to learn.
I'm playing with a graphics Windows application. I want to draw a simple graphics shape(rectangle, circle, line, etc) on a windows form and be able to move that graphics object anywhere on the form using the mouse.
Does anyone have any sample code that can draw a shape on the windows form and allow to move it with the mouse, or arrow keys?
Thanks in advance,
Quecumber256
|
|
|
|
|
If you want to learn, you would be better off writing the code yourself. How are you going to learn anything if someone else writes the code for you?
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
There are no built-in classes to do this, not is there any support built into GDI for this either.
What you're referring to is a "retained mode" graphics system. This is something that you either have to write yourself (WARNING! NOT for someone who has little experience!), or use a third party library to handle it for you, like VG.NET.
|
|
|
|