Delayed UI Code
am 23.01.2008 18:04:39 von Rory Becker
I am using Studio 2008 with .Net 3.5. and my Brain is Fried :)
My user will use typical 'next' and 'previous' buttons to navigate records
in my app.
They will sometimes be in the habit of hittting the next button repeatedly
not giving the screen time to finish refreshing it's current record before
moving to the next.
I would like my program to work like this....
------------------------------------------------------------ -
Sub JumpNextRecord()
Call ChangeRecordPointer
Call UpdateWinformElement1FromDB
Call UpdateWinformElement2FromDB
Call CallDelayed(AddressOf UpdateWinformElement3FromDB, 250)
End Sub
------------------------------------------------------------ -
'UpdateWinformElement1FromDB' and 'UpdateWinformElement2FromDB' are simple
methods but 'UpdateWinformElement3FromDB' is complex and time consuming and
therefore I would like to only call it once the user has remained on the
current record for 250 ms or more.
This would allow me to hit a NextRecord button 5 times really quickly and
for the system to only call 'UpdateWinformElement3FromDB' 1 time once I stop
doing that.
Does anyone know how to do this?
--
Rory
Re: Delayed UI Code
am 23.01.2008 22:28:28 von newsgroups_remove
Hi Rory,
see http://weblogs.asp.net/rweigelt/archive/2007/12/28/5512423.a spx for a
solution.
Kind regards,
Henning Krause
wrote in message
news:2081c03153678ca2bf92c624515@news.microsoft.com...
>I am using Studio 2008 with .Net 3.5. and my Brain is Fried :)
>
> My user will use typical 'next' and 'previous' buttons to navigate records
> in my app.
>
> They will sometimes be in the habit of hittting the next button repeatedly
> not giving the screen time to finish refreshing it's current record before
> moving to the next.
>
> I would like my program to work like this....
> ------------------------------------------------------------ -
> Sub JumpNextRecord()
> Call ChangeRecordPointer
> Call UpdateWinformElement1FromDB
> Call UpdateWinformElement2FromDB
> Call CallDelayed(AddressOf UpdateWinformElement3FromDB, 250)
> End Sub ------------------------------------------------------------ -
>
> 'UpdateWinformElement1FromDB' and 'UpdateWinformElement2FromDB' are simple
> methods but 'UpdateWinformElement3FromDB' is complex and time consuming
> and therefore I would like to only call it once the user has remained on
> the current record for 250 ms or more.
>
> This would allow me to hit a NextRecord button 5 times really quickly and
> for the system to only call 'UpdateWinformElement3FromDB' 1 time once I
> stop doing that.
>
> Does anyone know how to do this?
>
> --
> Rory
>
>
Re: Delayed UI Code
am 24.01.2008 12:02:18 von Rory Becker
Hello Henning Krause [MVP - Exchange],
> see http://weblogs.asp.net/rweigelt/archive/2007/12/28/5512423.a spx
> for a solution.
Thanks Henning
That's exactly what I was looking for.
I have had to do a little translation to VB.Net, but it's good to have to
do that sort of thing occasionally.
Either way it works perfectly
Thanks again.
Re: Delayed UI Code
am 24.01.2008 12:10:24 von jialge
Hello Rory,
From your post, my understanding on this issue is: you wonder how to avoid
a button click event raising several times due to rapid clicking. If I'm
off base, please feel free to let me know.
As Henning suggested, we can use a Timer object to resolve the problem. The
library "EventFilter" mentioned by Henning shows an example. Suppose the
"Next Button" object is btn_Next, we can call the following when the button
is initialized:
btn_Next.OnClick +=
m_objSelectedIndexChangedEventFilter.HandleOriginalEvent;
m_objSelectedIndexChangedEventFilter.FilteredEventRaised += JumpNextRecord;
where m_objSelectedIndexChangedEventFilter is a EventFilter object declared
as a member in the form class, and JumpNextRecord is the method that will
do the updatewinform work.
There is a const member "const int _DefaultTimeWindow = 150;" defind in the
EventFilter class. In order to change the wait time to 250ms as you
mentioned in the question, we can edit its value to 250.
Please have a try and feel free to let me know if you have any other
concerns or questions.
Regards,
Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/de fault.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx .
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Re: Delayed UI Code
am 24.01.2008 13:03:50 von Rory Becker
Yup it all works great.
My only issue would be my desire for a slightly more consise method of acheiving
this
I have been able to change from
------------------------------------------------------------ -
Public Sub New()
AddHandler Me.OnUpdateRolePanel, AddressOf UpdateRolePanel
End Sub
Public Sub Button1_Click(ByVal Sender As Object, ByVal e As EventArgs)
RaiseEvent OnMyUpdate(sender,e)
End Sub
------------------------------------------------------------ -
....to...
------------------------------------------------------------ -
Private MyEventFilter As New EventFilter(Of EventArgs)
Public Sub New()
AddHandler Me.OnMyUpdate, AddressOf MyEventFilter.HandleOriginalEvent
AddHandler MyEventFilter.FilteredEventRaised, AddressOf Me.MyUpdate
End Sub
Public Sub Button1_Click(ByVal Sender As Object, ByVal e As EventArgs)
RaiseEvent OnMyUpdate(sender,e)
End Sub
------------------------------------------------------------ -
I think it would be great if I could remove the Sub New delegating the setup
to the EventFilter's Constructor
------------------------------------------------------------ -
Private MyEventFilter As New EventFilter(Of EventArgs)(Me.OnMyUpdate, AddressOf
Me.MyUpdate)
Public Sub Button1_Click(ByVal Sender As Object, ByVal e As EventArgs)
RaiseEvent OnMyUpdate(sender,e)
End Sub
------------------------------------------------------------ -
But I can see no way to do this.
In any case, things are working and I cannot complain. ( I just wish it were
a little neater. I can see myself doing this quite a bit :))
--
Rory
Re: Delayed UI Code
am 24.01.2008 16:44:10 von jialge
Hello Rory,
According to the sample code (though it cannot pass compilation):
----------------------------------------
Private MyEventFilter As New EventFilter(Of EventArgs)(Me.OnMyUpdate,
AddressOf
Me.MyUpdate)
Public Sub Button1_Click(ByVal Sender As Object, ByVal e As EventArgs)
RaiseEvent OnMyUpdate(sender,e)
End Sub
----------------------------------------
Your expectation is to pass an "event object" to another class's
contructor, so that a event handler can be added to the "event object" in a
place hidden from the current form object. Right?
I have to let you know that we possibly cannot do it for .NET events. As is
mentioned in MSDN article
http://msdn2.microsoft.com/en-us/library/8627sbea(VS.80).asp x, events are a
special kind of multicast delegate that can *ONLY* be invoked from within
the class or struct where they are declared (the publisher class). But if
you insist doing this, here is a possible workaround from MSDN forum thread:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=273546 5&SiteID=1
class MainForm
{
public event ButtonClickEventHandler OnClick
{
add
{
m_buttonClick = (ButtonClickEventHandler
)Delegate.Combine(m_buttonClick, value);
}
...
}
public ButtonClickEventHandler m_buttonClick;
}
so we can then consider passing the delegate m_buttonClick to the
constructor of EventFilter.
Hope it helps.
Regards,
Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.