473,498 Members | 37 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Uncaught exception.

Airslash
221 New Member
Hello,

here is my code piece. I know it's ugly written, but the idea is that I recieve an image over TCP IP and try to display it in a picturebox.

Expand|Select|Wrap|Line Numbers
  1.                         try
  2.                         {
  3.                             WriteMessage("Image Data recieved.");
  4.                             int size = m_client.Available;
  5.                             WriteMessage("Image Size: " + size.ToString() + " bytes.");
  6.                             byte[] buffer = new byte[size];
  7.                             nstream.Read(buffer, 0, size);
  8.  
  9.                             MemoryStream mstream = new MemoryStream();
  10.                             mstream.Write(buffer, 0, size);
  11.  
  12.                             Image img = Image.FromStream(mstream);
  13.  
  14.                             m_display.Image = img;
  15.  
  16.                             img.Dispose();
  17.                             mstream.Close();
  18.  
  19.                             // Ask next image.
  20.                             WriteMessage("Asking next image.");
  21.                             byte[] request = Encoding.ASCII.GetBytes(txt_message.Text);
  22.  
  23.                             if (nstream.CanWrite)
  24.                             {
  25.                                 nstream.Write(request, 0, request.Length);
  26.                             }
  27.                             else
  28.                             {
  29.                                 WriteMessage("Can't write next request.");
  30.                             }
  31.                         }
  32.                         catch (Exception Ex)
  33.                         {
  34.                             WriteMessage(Ex.Message);
  35.                         }
  36.  
I'm getting an ArgumentException thrown here and I can't seem to catch , although the code is surrounded with try-catch blocks.
The argument exception complains about an invalid parameter is beeing related to image width. At least thats all I can tell from the exception.

The function itself it beeing called at a regular interval using a Threading.Timer class.

EDIT:
did some debugging, the image get's transfered correctly. Saved it to disk and it displays correctly. So no idea where the problem is comming from.
Aug 12 '10 #1
11 4737
Airslash
221 New Member
Here's the details of the exception

Expand|Select|Wrap|Line Numbers
  1. System.ArgumentException was unhandled
  2.   Message=Parameter is not valid.
  3.   Source=System.Drawing
  4.   StackTrace:
  5.        at System.Drawing.Image.get_Width()
  6.        at System.Drawing.Image.get_Size()
  7.        at System.Windows.Forms.PictureBox.ImageRectangleFromSizeMode(PictureBoxSizeMode mode)
  8.        at System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
  9.        at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
  10.        at System.Windows.Forms.Control.WmPaint(Message& m)
  11.        at System.Windows.Forms.Control.WndProc(Message& m)
  12.        at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
  13.        at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
  14.        at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  15.        at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
  16.        at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
  17.        at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
  18.        at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
  19.        at System.Windows.Forms.Application.Run(Form mainForm)
  20.        at VTTest.Program.Main() in E:\Source Code\CurrentRelease\Visual Studio\UnitTests\VTTest\VTTest\Program.cs:line 18
  21.        at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
  22.        at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
  23.        at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
  24.        at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
  25.        at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
  26.        at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
  27.        at System.Threading.ThreadHelper.ThreadStart()
  28.   InnerException: 
  29.  
So if I understand this correctly, the problem is related with drawing the image on the display?
Aug 12 '10 #2
Aimee Bailey
197 Recognized Expert New Member
You are disposing the image before m_display has time to render it, let the garbage collector do it for you and you may find it works. Also, make sure to catch more specific exceptions, using the base Exception class means that you get only a general handler for the exception.

Best of luck :)

Aimee.
Aug 12 '10 #3
Airslash
221 New Member
Why is the solution always this bloody simple.....


I have removed the dispose and it works....Still getting an invalid parameter exception now and then but the images get displayed at least.

I've noticed that I have a serious "lag" on the display and alot of the images get corrupt on the display. Is this a transfer issue between server & client, or am I simply overwriting them too fast?
Aug 12 '10 #4
GaryTexmo
1,501 Recognized Expert Top Contributor
Oh this exception.. ugh, yea I've encounters this too.

The details are fuzzy, but I think when you dispose that object it destroys something the memory stream is holding onto.
Aug 12 '10 #5
Aimee Bailey
197 Recognized Expert New Member
Something else I just noticed, should you be using the Image class, or its base class Bitmap?
Aug 12 '10 #6
GaryTexmo
1,501 Recognized Expert Top Contributor
Oops, nevermind my last post. I misread and thought you were doing something else.

That said, I don't think you can close the memory stream. When I was fooling around with loading images and I closed the memory stream, I would get that exception... I think. I'm going to have to dig through my example project.
Aug 12 '10 #7
Airslash
221 New Member
I'll give it a go without closing or disposing stuff. Might move them to class members and simply reuse them.

Currently I'm using the Image base class because I'm loading jpeg from a TCP stream.Whether or not these remain jpeg I don't know yet.
I'm simply trying to emulate a videostream, because I don't want to use a third-party component to render avi streams.

In theory this should work just as well :S
Aug 13 '10 #8
Aimee Bailey
197 Recognized Expert New Member
One question, are you loading them one by one? or are you buffering a couple at a time before playing?

Stupid question I know, but have to ask :$
Aug 13 '10 #9
Airslash
221 New Member
I'm loading them one by one.

The idea is that the client requests an Image, this image gets loaded & transfered. Then the client displays the image and sends the next request.

So it's practicly the bandwith + client processing speed that determine the speed of the transfer.

I have set the NoDelay option to true on my TcpListener/Client to make sure that the transfers don't have to wait for a full buffer.
Aug 13 '10 #10
Airslash
221 New Member
Update:

Setting the NoDelay on the client to true, but false on the server seems to produce the fastest results at the moment.
Aug 13 '10 #11
Airslash
221 New Member
UPDATE:

Well after playing around with various settings and making a lot of configurable, I've found some conclusions:

- The client polls the line every 10ms
- The server polls the line every 75ms
- The client sends a request and receives image data.
- The client needs around 16ms to send a request, get a reply and render the whole image.
- The server needs 100ms to complete a request, because the UDP response from the third applications takes so long.

Is it correct to conclude that the TCP connection works as intended, but that the following issues occur:

- Server gets slowed down due the UDP taking so long
- THe client 'lags' because I overwrite the image faster then its beeing displayed
Aug 13 '10 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3170
by: nrhayyal | last post by:
hi all, i am facing a problem in catching an exception which is uncaught in any of the catch block. not doing so will gives me coredump. I tried by rewriting set_unexpected() and set_terminate()...
7
2456
by: meaneyedcat | last post by:
When I call addField(), my table appears to be populated correctly with a new row in the table with all the required fields. However, when I call delete row on any new rows that have been created,...
3
3439
by: c.prerovsky | last post by:
Hi there, I started messing around with JavaScript OOP a few days ago and still can't get this one to work. There are many things wich keep confusing me, eg. the various ways to define a class...
5
3447
by: -Lost | last post by:
Error: uncaught exception: " nsresult: "0x80004001 (NS_ERROR_NOT_IMPLEMENTED)" location: "JS frame :: file:///D:/sites/_test/js/iterate_document.htm :: <TOP_LEVEL:: line 15" data: no] Line 15...
2
36669
Plater
by: Plater | last post by:
I am using the XMLHttpRequest to send a request every 5ish seconds or so. Everything works fine until I take the server down that the object is trying to retrieve data from. Then the firefox...
9
14128
by: xhunter | last post by:
Hi, I have written my code to load some content through ajax, which works perfectly, then I thought of adding a timeout to retry the action in case it has failed or something. here is the code...
3
2521
by: George2 | last post by:
Hello everyone, Just want to check whether my understanding is correct, Both (1) and (2) only covers Windows C++ platform. 1. If there is uncaught exception, destructor is not ensured to...
2
7449
by: josephx | last post by:
Hello, I got some of these errors listed below after executing an HTTP Post MIDlet on CLDC/MIDP platform, "Nokia S40 DP 2.0 SDK 1.1" and "S40 5th Edition SDK Feature Pack 1" and even for S60's...
3
3730
by: friend | last post by:
Error: uncaught exception: " nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://manimekalai/VulnMgmt/scanfi/crs_source/vulnupdate/latest.php?vulnerability=2451 ::...
0
7124
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6998
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4904
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4586
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.