473,399 Members | 3,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

How to make this better and faster?

I have written the following Win app in VB.NET 2003 . The class is simply
picture boxes that behave in a random order after they have been
instantiated and added to a form. When I create 15 or more instances of my
class, the whole program runs slowly in a way that I have to close the
program. I have tried to create a new thread for each class, but that throws
an exception , because a separated thread can't be added to a form from a
child class.

My code is this ( please tell me if there are better ways for doing it)
coplile with :

vbc [filename]
/r:system.dll,system.windows.forms.dll,system.drawi ng.dll,microsoft.visualbasic.dll
/t:winexe /main:form1

'----------------------------------- Start of CODE

Imports System.Math
imports Microsoft.VisualBasic
imports System.drawing
imports system.windows.forms

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.Color.White
Me.ClientSize = New System.Drawing.Size(384, 266)
Me.Name = "Form1"
Me.Text = "Form1"

End Sub

#End Region

Private Sub Form1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click
CreateOBJ()
End Sub
Sub CreateOBJ()
Dim myRec As Rec = New Rec(Me.CreateGraphics, Me)
End Sub
End Class

'--------------------------------------------------- Class Rec

Public Class Rec

Dim Gr As Graphics
Dim X, Y As Integer
Dim frm As Form
WithEvents TIMER As New Timer
Dim bmp As Bitmap
Dim PB As PictureBox

Public Sub New(ByVal g As Graphics, ByVal form As Form)
X = Rnd() * 100
Y = Rnd() * 200
Gr = g
Me.frm = form
ini()
justAddX = True
justAddY = True
End Sub

' We could use the graphics object here to draw on the form. But since
GDI+
' lacks the ideal performance, we use picture boxes and add them to the
' spacified form instead of using the drawing object:

Sub ini()
TIMER.Interval = Rnd() * 10 + 1
TIMER.Enabled = True
PB = New PictureBox
With PB
.BackColor = Color.FromArgb(Rnd() * 150, Rnd() * 200, Rnd() *
230)
.Left = X
.Top = Y
.Height = 6
.Width = 6
End With
frm.Controls.Add(PB)
End Sub

' Use these two boolean to know when to add or substarct numbers
' the movement of this class object.
Dim justAddX, justAddY As Boolean

Private Sub TIMER_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TIMER.Tick
MoveMe()
End Sub

' CuurentNum X , Y are the numbers added to the speed of X ,Y
' which creates a kind of change when the Rec hits the walls:

Dim CurrentNumX As Integer = 1
Dim CurrentNumY As Integer = 1

Sub MoveMe()
If X > (frm.Width - PB.Width) - 10 Then
justAddX = False
CurrentNumX = Rnd() * 50
End If

If Y > (frm.Height - PB.Height) - 30 Then
justAddY = False
CurrentNumY = Rnd() * 40
End If

If X < 0 Then
justAddX = True
CurrentNumX = Rnd() * 80
End If

If Y < 0 Then
justAddY = True
CurrentNumY = Rnd() * 30
End If

If justAddX Then
X += CurrentNumX
Else
X -= CurrentNumX
End If

If justAddY Then
Y += CurrentNumY
Else
Y -= CurrentNumY
End If

PB.Left = X
PB.Top = Y
End Sub

End Class
'------------------------------------------------------- End of
CODE------------

Jul 21 '05 #1
15 1655
You might want to check into the API routine BitBlt. It copies rectangle
shapes from and to graphics objects. It's very, very fast. You could draw
your images directly on the form using the Paint event.

"ham-z" wrote:
I have written the following Win app in VB.NET 2003 . The class is simply
picture boxes that behave in a random order after they have been
instantiated and added to a form. When I create 15 or more instances of my
class, the whole program runs slowly in a way that I have to close the
program. I have tried to create a new thread for each class, but that throws
an exception , because a separated thread can't be added to a form from a
child class.

My code is this ( please tell me if there are better ways for doing it)
coplile with :

vbc [filename]
/r:system.dll,system.windows.forms.dll,system.drawi ng.dll,microsoft.visualbasic.dll
/t:winexe /main:form1

'----------------------------------- Start of CODE

Imports System.Math
imports Microsoft.VisualBasic
imports System.drawing
imports system.windows.forms

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.Color.White
Me.ClientSize = New System.Drawing.Size(384, 266)
Me.Name = "Form1"
Me.Text = "Form1"

End Sub

#End Region

Private Sub Form1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click
CreateOBJ()
End Sub
Sub CreateOBJ()
Dim myRec As Rec = New Rec(Me.CreateGraphics, Me)
End Sub
End Class

'--------------------------------------------------- Class Rec

Public Class Rec

Dim Gr As Graphics
Dim X, Y As Integer
Dim frm As Form
WithEvents TIMER As New Timer
Dim bmp As Bitmap
Dim PB As PictureBox

Public Sub New(ByVal g As Graphics, ByVal form As Form)
X = Rnd() * 100
Y = Rnd() * 200
Gr = g
Me.frm = form
ini()
justAddX = True
justAddY = True
End Sub

' We could use the graphics object here to draw on the form. But since
GDI+
' lacks the ideal performance, we use picture boxes and add them to the
' spacified form instead of using the drawing object:

Sub ini()
TIMER.Interval = Rnd() * 10 + 1
TIMER.Enabled = True
PB = New PictureBox
With PB
.BackColor = Color.FromArgb(Rnd() * 150, Rnd() * 200, Rnd() *
230)
.Left = X
.Top = Y
.Height = 6
.Width = 6
End With
frm.Controls.Add(PB)
End Sub

' Use these two boolean to know when to add or substarct numbers
' the movement of this class object.
Dim justAddX, justAddY As Boolean

Private Sub TIMER_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TIMER.Tick
MoveMe()
End Sub

' CuurentNum X , Y are the numbers added to the speed of X ,Y
' which creates a kind of change when the Rec hits the walls:

Dim CurrentNumX As Integer = 1
Dim CurrentNumY As Integer = 1

Sub MoveMe()
If X > (frm.Width - PB.Width) - 10 Then
justAddX = False
CurrentNumX = Rnd() * 50
End If

If Y > (frm.Height - PB.Height) - 30 Then
justAddY = False
CurrentNumY = Rnd() * 40
End If

If X < 0 Then
justAddX = True
CurrentNumX = Rnd() * 80
End If

If Y < 0 Then
justAddY = True
CurrentNumY = Rnd() * 30
End If

If justAddX Then
X += CurrentNumX
Else
X -= CurrentNumX
End If

If justAddY Then
Y += CurrentNumY
Else
Y -= CurrentNumY
End If

PB.Left = X
PB.Top = Y
End Sub

End Class
'------------------------------------------------------- End of
CODE------------

Jul 21 '05 #2
Ham,

Nice crossposting, however the in my opinion most right newsgroup for this
question is not in it.

microsoft.public.dotnet.framework.drawing

I saw your problem, however I think because the fact that the most is
graphics you can place it the best in that newsgroup.

No problem at all that crossposting by the way.

Cor

"ham-z" <hamz-3e@/**/yahoo.com>.
I have written the following Win app in VB.NET 2003 . The class is simply
picture boxes that behave in a random order after they have been
instantiated and added to a form. When I create 15 or more instances of my
class, the whole program runs slowly in a way that I have to close the
program. I have tried to create a new thread for each class, but that
throws
an exception , because a separated thread can't be added to a form from a
child class.

My code is this ( please tell me if there are better ways for doing it)
coplile with :

vbc [filename]
/r:system.dll,system.windows.forms.dll,system.drawi ng.dll,microsoft.visualbasic.dll
/t:winexe /main:form1

'----------------------------------- Start of CODE

Imports System.Math
imports Microsoft.VisualBasic
imports System.drawing
imports system.windows.forms

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.Color.White
Me.ClientSize = New System.Drawing.Size(384, 266)
Me.Name = "Form1"
Me.Text = "Form1"

End Sub

#End Region

Private Sub Form1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click
CreateOBJ()
End Sub
Sub CreateOBJ()
Dim myRec As Rec = New Rec(Me.CreateGraphics, Me)
End Sub
End Class

'--------------------------------------------------- Class Rec

Public Class Rec

Dim Gr As Graphics
Dim X, Y As Integer
Dim frm As Form
WithEvents TIMER As New Timer
Dim bmp As Bitmap
Dim PB As PictureBox

Public Sub New(ByVal g As Graphics, ByVal form As Form)
X = Rnd() * 100
Y = Rnd() * 200
Gr = g
Me.frm = form
ini()
justAddX = True
justAddY = True
End Sub

' We could use the graphics object here to draw on the form. But since
GDI+
' lacks the ideal performance, we use picture boxes and add them to the
' spacified form instead of using the drawing object:

Sub ini()
TIMER.Interval = Rnd() * 10 + 1
TIMER.Enabled = True
PB = New PictureBox
With PB
.BackColor = Color.FromArgb(Rnd() * 150, Rnd() * 200, Rnd() *
230)
.Left = X
.Top = Y
.Height = 6
.Width = 6
End With
frm.Controls.Add(PB)
End Sub

' Use these two boolean to know when to add or substarct numbers
' the movement of this class object.
Dim justAddX, justAddY As Boolean

Private Sub TIMER_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TIMER.Tick
MoveMe()
End Sub

' CuurentNum X , Y are the numbers added to the speed of X ,Y
' which creates a kind of change when the Rec hits the walls:

Dim CurrentNumX As Integer = 1
Dim CurrentNumY As Integer = 1

Sub MoveMe()
If X > (frm.Width - PB.Width) - 10 Then
justAddX = False
CurrentNumX = Rnd() * 50
End If

If Y > (frm.Height - PB.Height) - 30 Then
justAddY = False
CurrentNumY = Rnd() * 40
End If

If X < 0 Then
justAddX = True
CurrentNumX = Rnd() * 80
End If

If Y < 0 Then
justAddY = True
CurrentNumY = Rnd() * 30
End If

If justAddX Then
X += CurrentNumX
Else
X -= CurrentNumX
End If

If justAddY Then
Y += CurrentNumY
Else
Y -= CurrentNumY
End If

PB.Left = X
PB.Top = Y
End Sub

End Class
'------------------------------------------------------- End of
CODE------------

Jul 21 '05 #3
"Dennis" <De****@discussions.microsoft.com> schrieb:
You might want to check into the API routine BitBlt. It copies rectangle
shapes from and to graphics objects. It's very, very fast. You could
draw
your images directly on the form using the Paint event.


I doubt that this will be much faster than 'Graphics.DrawImage[Unscaled]'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jul 21 '05 #4
OK, so you have a form that **VERY QUICKLY** moves boxes at random around
the screen.
Realize that your timer ticks are happening so quickly that the system will
be queueing events and colliding with itself on each form, and that will
only get worse with additional forms.

I'm not sure what you are trying to prove with this graphics exercise. If
you want to see how fast graphics can move, than causing a timer conflict is
probably not the best way to go about it. If you are trying to see how the
OS handles PAINT events, then you may want to have a single form and stress
it, rather than using a timer at all.

Also, your timer is declared in the object, not in the form. The means that
every new object you create will create a new timer. This may be a trivial
point, but I'd recommend that you move the timer to the form.

More importantly, to make your window perform, I'd suggest you change a
single line.
from: TIMER.Interval = Rnd() * 10 + 1
from: TIMER.Interval = Rnd() * 10 + 100

That will give you 10 Paint events per second per form, which is still
plenty fast enough but is less likely to cause a pile-up.
--
--- Nick Malik [MSFT]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.

"ham-z" <hamz-3e@/**/yahoo.com> wrote in message
news:Ot**************@TK2MSFTNGP10.phx.gbl...
I have written the following Win app in VB.NET 2003 . The class is simply
picture boxes that behave in a random order after they have been
instantiated and added to a form. When I create 15 or more instances of my
class, the whole program runs slowly in a way that I have to close the
program. I have tried to create a new thread for each class, but that throws an exception , because a separated thread can't be added to a form from a
child class.

My code is this ( please tell me if there are better ways for doing it)
coplile with :

vbc [filename]
/r:system.dll,system.windows.forms.dll,system.drawi ng.dll,microsoft.visualba
sic.dll /t:winexe /main:form1

'----------------------------------- Start of CODE

Imports System.Math
imports Microsoft.VisualBasic
imports System.drawing
imports system.windows.forms

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.Color.White
Me.ClientSize = New System.Drawing.Size(384, 266)
Me.Name = "Form1"
Me.Text = "Form1"

End Sub

#End Region

Private Sub Form1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click
CreateOBJ()
End Sub
Sub CreateOBJ()
Dim myRec As Rec = New Rec(Me.CreateGraphics, Me)
End Sub
End Class

'--------------------------------------------------- Class Rec

Public Class Rec

Dim Gr As Graphics
Dim X, Y As Integer
Dim frm As Form
WithEvents TIMER As New Timer
Dim bmp As Bitmap
Dim PB As PictureBox

Public Sub New(ByVal g As Graphics, ByVal form As Form)
X = Rnd() * 100
Y = Rnd() * 200
Gr = g
Me.frm = form
ini()
justAddX = True
justAddY = True
End Sub

' We could use the graphics object here to draw on the form. But since
GDI+
' lacks the ideal performance, we use picture boxes and add them to the ' spacified form instead of using the drawing object:

Sub ini()
TIMER.Interval = Rnd() * 10 + 1
TIMER.Enabled = True
PB = New PictureBox
With PB
.BackColor = Color.FromArgb(Rnd() * 150, Rnd() * 200, Rnd() *
230)
.Left = X
.Top = Y
.Height = 6
.Width = 6
End With
frm.Controls.Add(PB)
End Sub

' Use these two boolean to know when to add or substarct numbers
' the movement of this class object.
Dim justAddX, justAddY As Boolean

Private Sub TIMER_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TIMER.Tick
MoveMe()
End Sub

' CuurentNum X , Y are the numbers added to the speed of X ,Y
' which creates a kind of change when the Rec hits the walls:

Dim CurrentNumX As Integer = 1
Dim CurrentNumY As Integer = 1

Sub MoveMe()
If X > (frm.Width - PB.Width) - 10 Then
justAddX = False
CurrentNumX = Rnd() * 50
End If

If Y > (frm.Height - PB.Height) - 30 Then
justAddY = False
CurrentNumY = Rnd() * 40
End If

If X < 0 Then
justAddX = True
CurrentNumX = Rnd() * 80
End If

If Y < 0 Then
justAddY = True
CurrentNumY = Rnd() * 30
End If

If justAddX Then
X += CurrentNumX
Else
X -= CurrentNumX
End If

If justAddY Then
Y += CurrentNumY
Else
Y -= CurrentNumY
End If

PB.Left = X
PB.Top = Y
End Sub

End Class
'------------------------------------------------------- End of
CODE------------

Jul 21 '05 #5
It's OK on my machine even when I created 200 instances of rec. My machine
is: Intel(R) Pentium (R) 4 CPU 2.40GHZ | AT/AT COMPATIBLE | 1G RAM

Jul 21 '05 #6
What you need is a single control, not multiple PictureBoxes, that you draw
on. Create a custom control class, double buffered, that draws everything
you need. Multi-threading is unnecessary and will only cause tragedy.

To see the maximum performance you can get from GDI+ try the Scalability
sample source in the VG.net Lite installation. It uses an optimized run-time
engine layered on GDI+. You can create and time 1K-100K rectangles. The
timing framework can be reused to benchmark other implementations.

Regards,
Frank Hileman

check out VG.net: http://www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio .NET graphics editor
"ham-z" <hamz-3e@/**/yahoo.com> wrote in message
news:Ot**************@TK2MSFTNGP10.phx.gbl...
I have written the following Win app in VB.NET 2003 . The class is simply
picture boxes that behave in a random order after they have been
instantiated and added to a form. When I create 15 or more instances of my
class, the whole program runs slowly in a way that I have to close the
program. I have tried to create a new thread for each class, but that
throws
an exception , because a separated thread can't be added to a form from a
child class.

My code is this ( please tell me if there are better ways for doing it)
coplile with :

vbc [filename]
/r:system.dll,system.windows.forms.dll,system.drawi ng.dll,microsoft.visualbasic.dll
/t:winexe /main:form1

'----------------------------------- Start of CODE

Imports System.Math
imports Microsoft.VisualBasic
imports System.drawing
imports system.windows.forms

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.Color.White
Me.ClientSize = New System.Drawing.Size(384, 266)
Me.Name = "Form1"
Me.Text = "Form1"

End Sub

#End Region

Private Sub Form1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click
CreateOBJ()
End Sub
Sub CreateOBJ()
Dim myRec As Rec = New Rec(Me.CreateGraphics, Me)
End Sub
End Class

'--------------------------------------------------- Class Rec

Public Class Rec

Dim Gr As Graphics
Dim X, Y As Integer
Dim frm As Form
WithEvents TIMER As New Timer
Dim bmp As Bitmap
Dim PB As PictureBox

Public Sub New(ByVal g As Graphics, ByVal form As Form)
X = Rnd() * 100
Y = Rnd() * 200
Gr = g
Me.frm = form
ini()
justAddX = True
justAddY = True
End Sub

' We could use the graphics object here to draw on the form. But since
GDI+
' lacks the ideal performance, we use picture boxes and add them to the
' spacified form instead of using the drawing object:

Sub ini()
TIMER.Interval = Rnd() * 10 + 1
TIMER.Enabled = True
PB = New PictureBox
With PB
.BackColor = Color.FromArgb(Rnd() * 150, Rnd() * 200, Rnd() *
230)
.Left = X
.Top = Y
.Height = 6
.Width = 6
End With
frm.Controls.Add(PB)
End Sub

' Use these two boolean to know when to add or substarct numbers
' the movement of this class object.
Dim justAddX, justAddY As Boolean

Private Sub TIMER_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TIMER.Tick
MoveMe()
End Sub

' CuurentNum X , Y are the numbers added to the speed of X ,Y
' which creates a kind of change when the Rec hits the walls:

Dim CurrentNumX As Integer = 1
Dim CurrentNumY As Integer = 1

Sub MoveMe()
If X > (frm.Width - PB.Width) - 10 Then
justAddX = False
CurrentNumX = Rnd() * 50
End If

If Y > (frm.Height - PB.Height) - 30 Then
justAddY = False
CurrentNumY = Rnd() * 40
End If

If X < 0 Then
justAddX = True
CurrentNumX = Rnd() * 80
End If

If Y < 0 Then
justAddY = True
CurrentNumY = Rnd() * 30
End If

If justAddX Then
X += CurrentNumX
Else
X -= CurrentNumX
End If

If justAddY Then
Y += CurrentNumY
Else
Y -= CurrentNumY
End If

PB.Left = X
PB.Top = Y
End Sub

End Class
'------------------------------------------------------- End of
CODE------------

Jul 21 '05 #7
Nick Malik [MSFT] wrote:
OK, so you have a form that **VERY QUICKLY** moves boxes at random around
the screen.
Realize that your timer ticks are happening so quickly that the system
will
be queueing events and colliding with itself on each form, and that will
only get worse with additional forms.
Nice hint, but my PB object is responsible for it's own movement. It should
have a built-in timer in order to move

I'm not sure what you are trying to prove with this graphics exercise.
creating sth alive...look at this if you have MSDN 2003 installed:
ms-help://MS.MSDNQTR.2003APR.1033/dndllpro/html/msdn_frogfly1.htm

Also, your timer is declared in the object, not in the form. The means
that
every new object you create will create a new timer. This may be a
trivial
point, but I'd recommend that you move the timer to the form.
How? each object is responsible for its own movement....
More importantly, to make your window perform, I'd suggest you change a
single line.
from: TIMER.Interval = Rnd() * 10 + 1
from: TIMER.Interval = Rnd() * 10 + 100

That will give you 10 Paint events per second per form, which is still
plenty fast enough but is less likely to cause a pile-up.


Nice suggestion.
Thanks anyway for help.

Jul 21 '05 #8
You got plenty of RAM.... mine is only 256 MB...though I can't figure out
what 1 GB RAM might do for this ( almost no relation) comparing with
256.....
"Rulin Hong" <Ru*******@discussions.microsoft.com> wrote in message
news:DC**********************************@microsof t.com...
It's OK on my machine even when I created 200 instances of rec. My machine
is: Intel(R) Pentium (R) 4 CPU 2.40GHZ | AT/AT COMPATIBLE | 1G RAM

Jul 21 '05 #9
I looked at the MSDN reference. This is a good example of all the problems
you can have by using mutiple threads when they are not needed. It is a poor
article. The author believes mutiple threads are needed to update internal
state, even though the output is serialized to a single thread -- he is
perpetuating common misunderstandings.

In a simulation of multiple actors, the simplest single threaded approach is
to loop through all the actors when a Windows.Forms.Timer fires, updating
their internal state, then force a paint event to occur (invalidate modified
areas). The paint cannot occur faster than the timer in any circumstance, so
intermediate state changes are wasteful. If you need the state changes to be
dependent on the passage of time, you can use the Win32 high performance
timer to accurately determine elapsed time from the beginning of the
simulation, QueryPerformanceCounter (a wrapper class is in the sample I
mentioned).

In the unlikely event the number of actors is so large that updating
internal state causes the UI to become unresponsive, you can process a
fixed, smaller number of actors on each timer tick, incrementing a processed
actor counter, avoiding invalidation of the control until all have been
processed. This is a second technique for avoiding multi-threading when it
is not needed, while maintaining a responsive UI. If you use this approach,
you should determine elapsed time, for the purpose of state changes, at the
first tick after a complete update, so that all actors work with a
consistent time base.

To get great drawing performance use multiple graphical objects drawn on a
single control, instead of multiple controls.

Regards,
Frank Hileman

check out VG.net: http://www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio .NET graphics editor
"ham-z" <hamz-3e@/**/yahoo.com> wrote in message
news:eO**************@TK2MSFTNGP11.phx.gbl...
Nick Malik [MSFT] wrote:
creating sth alive...look at this if you have MSDN 2003 installed:
ms-help://MS.MSDNQTR.2003APR.1033/dndllpro/html/msdn_frogfly1.htm

Jul 21 '05 #10
Are you saying that BitBlt is not any faster than .drawimage? It seems
faster to me and I have read articles on the web that also say it's much
faster.

"Herfried K. Wagner [MVP]" wrote:
"Dennis" <De****@discussions.microsoft.com> schrieb:
You might want to check into the API routine BitBlt. It copies rectangle
shapes from and to graphics objects. It's very, very fast. You could
draw
your images directly on the form using the Paint event.


I doubt that this will be much faster than 'Graphics.DrawImage[Unscaled]'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jul 21 '05 #11
"Dennis" <De****@discussions.microsoft.com> schrieb:
Are you saying that BitBlt is not any faster than .drawimage? It seems
faster to me and I have read articles on the web that also say it's much
faster.


I didn't check it in all details, but I assume that 'DrawImageUnscaled' is
approx. as fast as 'BitBlt' because it is a wrapper around 'BitBlt'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jul 21 '05 #12
Don't assume.
DrawImageUnscaled is not a wrapper around BitBlt. DrawImageUnscaled
just calls DrawImage. DrawImage calls the native function
GdipDrawImageI, which isn't as fast as BitBlt.
GdipDrawImageI uses GDI+, BitBlt uses GDI. GDI+ isn't hardware
accelerated, GDI is.

Jul 21 '05 #13
"Tommy" <to***********@telenet.be> schrieb:
Don't assume.
DrawImageUnscaled is not a wrapper around BitBlt. DrawImageUnscaled
just calls DrawImage. DrawImage calls the native function
GdipDrawImageI


You are right. IIRC what I said was written in "Professional C#" published
by Wrox. ILDASM shows that 'DrawImageUnscaled' simply calls 'DrawImage',
and 'DrawImage' is a wrapper around 'GdipDrawImageRectI'. Thank you for
making me aware of that.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jul 21 '05 #14
I don't use ILDASM, I use Reflector. It's much better than ILDASM, and
it decompiles the assembly in the language you want (included
languages: C#, VB.NET, IL, Delphi). http://www.aisto.com/roeder/dotnet

Jul 21 '05 #15
I don't use ILDASM, I use Reflector. It's much better than ILDASM, and
it decompiles the assembly in the language you want (included
languages: C#, VB.NET, IL, Delphi). http://www.aisto.com/roeder/dotnet

Jul 21 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Duncan Lissett | last post by:
I'd appreciate any suggestions on how to make faster Python implementations of Richards benchmark. Perhaps there are obvious problems that can be corrected? http://www.lissett.com/ben/bench1.htm
14
by: Wolfgang Keller | last post by:
Hello, as a non-developer I am currently participating in an industrial "research" project to develop a so-called "web application". This application serves at the same time as middleware to...
19
by: pkilambi | last post by:
I wrote this function which does the following: after readling lines from file.It splits and finds the word occurences through a hash table...for some reason this is quite slow..can some one...
15
by: ham-z | last post by:
I have written the following Win app in VB.NET 2003 . The class is simply picture boxes that behave in a random order after they have been instantiated and added to a form. When I create 15 or more...
8
by: Scott Emick | last post by:
I am using the following to compute distances between two lat/long coordinates for a store locator - (VB .NET 2003) it seems to take a long time to iterate through like 100-150 locations -...
10
by: Extremest | last post by:
I know there are ways to make this a lot faster. Any newsreader does this in seconds. I don't know how they do it and I am very new to c#. If anyone knows a faster way please let me know. All...
19
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; ...
3
by: salad | last post by:
I have an A97 application that is NOT split on a network. It is used by 15+ folks continually. It is quick and fast. I split it several years ago and had to merge it together again after the...
13
by: Simply_Red | last post by:
Hi, is there a way to make this function faster??? struct Points { double X; double Y; };
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.