|
Holmes> It represents the number of milliseconds the system takes to complete the processing loop from the VM.
I was waiting for this sentence.
For what this stands for? I mean, e.g. a label with mentioned milliseconds inside, on UI screen.
Just show to UI user that app is alive?
modified 5-Sep-18 4:36am.
|
|
|
|
|
Pew_new wrote: The major question is what do we really have valuable when we do a substraction as follows: ScanTime = DateTime.Now - _lastScanTime ? I cannot see anything 'valuable' in this. It merely gives you the actual elapsed time between the timer start and the first tick. Since your timer interval is set at 250 (milliseconds) it should be somewhere around that value. The question really is what this code is being used for?
|
|
|
|
|
Richard MacCutchan> The question really is what this code is being used for?
I would ask you this way.
My guess is it provides an UI user some kind of "Warning". Something like "Your PC's processor is so busy that the ScanTime went out of allowed time range." Of course in case when value is out of tolerance "window". A value is out of tolerancee "window" - text of value is highlighted with red.
modified 5-Sep-18 4:40am.
|
|
|
|
|
So why exactly are you asking here? We have no information on the context that this code runs inside, or what the application is trying to do.
|
|
|
|
|
Some info I gave in the first post:
Timer -> Timer procedure and calculation -> MVVM pattern -> UI.
As said Mr.Holmes. It's very simple code.
modified 5-Sep-18 5:08am.
|
|
|
|
|
Which means absolutely nothing. I still do not understand exactly what you are asking.
|
|
|
|
|
It may close this topic. I've got comrehensive answer from Mr.Holmes.
If you're interested in. This is answer: It represents the number of milliseconds the system takes to complete the processing loop from the VM.
|
|
|
|
|
No, it is just the number of milliseconds between the timer starting, and the Elapsed event being fired. This will occur after approximately 250 milliseconds as declared by the timer intialisation values.
|
|
|
|
|
Richard MacCutchan wrote: This will occur after approximately 250 milliseconds as declared by the timer intialisation values.
Ah crap I completely missed that, even after rereading the dammed code.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
We've all done that from time to time. Although, I was actually worried that I was missing something that you had noticed.
|
|
|
|
|
There appear to be a couple of structural issues with this code. The first thing is, you haven't shown us the complete class. Secondly, you update _lastScanTime to a different DateTime.Now than when you update ScanTime - in a multi-threaded application, this could be a potentially significant difference because of your ValuesRefreshed. To be honest, I don't know why you don't make ScanTime raise INotifyPropertyChanged.PropertyChanged and avoid other events; you can bind directly to that value. Also, I would use a StopWatch instead of DateTime.Now if I were you.
This space for rent
|
|
|
|
|
|
Yes. It's not going to be trivial though.
This space for rent
|
|
|
|
|
Hello everyone.
Currently I am trying to work with timers in WPF.
private void Window_Loaded(object sender, RoutedEventArgs e)
{
_timer = new System.Timers.Timer();
_timer.Interval = 1000;
_timer.Elapsed += OnTimerElapsed;
_timer.Start();
}
int i=0;
private void OnTimerElapsed(object sender, ElapsedEventArgs e)
{
i++;
label1.Content = i.ToString();
}
I've got an exception at this string
label1.Content = i.ToString();
What I'm doing wrong with a label?
Thanks in advance!
XAML:
<Label x:Name="label1" HorizontalAlignment="Center" Margin="2" VerticalAlignment="Center" Height="79" Width="86"/>
modified 3-Sep-18 4:19am.
|
|
|
|
|
Pew_new wrote: What I'm doing wrong with a label?
You access it from a different thread - you must not do that, and that holds true also for other UI technologies like WinForms.
With WPF also comes MVVM. Instead of setting the Content property directly, you bind it to some property of your view model. When that property changes, you raise an PropertyChanged event, and that will do the magic of "transporting" the change in the correct thread.
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
Please explain where have you seen " different thread"?
"different thread", you mean that with a System.Timer it's not possible?
P.S. Here https://www.youtube.com/watch?v=QkT8fgoFz3g, a guy is doing that easily. True he's using a Dispatcher Timer. So what's difference?
modified 3-Sep-18 5:17am.
|
|
|
|
|
The DispatcherTimer documentation makes things slightly clearer than the System.Timers.Timer documentation:
If a System.Timers.Timer is used in a WPF application, it is worth noting that the System.Timers.Timer runs on a different thread than the user interface (UI) thread. In order to access objects on the user interface (UI) thread, it is necessary to post the operation onto the Dispatcher of the user interface (UI) thread using Invoke or BeginInvoke .
Reasons for using a DispatcherTimer as opposed to a System.Timers.Timer are that the DispatcherTimer runs on the same thread as the Dispatcher and a DispatcherPriority can be set on the DispatcherTimer .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
No.
It doesn't quite work like that.
We do not do your work for you.
If you want someone to write your code, you have to pay - I suggest you go to Freelancer.com and ask there.
But be aware: you get what you pay for. Pay peanuts, get monkeys.
The idea of "development" is as the word suggests: "The systematic use of scientific and technical knowledge to meet specific objectives or requirements." BusinessDictionary.com[^]
That's not the same thing as "have a quick google and give up if I can't find exactly the right code".
So either pay someone to do it, or learn how to write it yourself. We aren't here to do it for you.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Talk of money? If I were Moderator I would ban such posts (where there are talks of money). Because it is a sure sign of soon dying of the resource.
PostScriptum: One of the principles of Free Internet sounds right about "peanuts and useful monkeys". Otherwise, a resource will die.
Hope this helps.
|
|
|
|
|
We have a very firm policy on spam (and yes, I'm a moderator) and my post doesn't even come close to approaching it.
You are demanding that someone here should do your work for you, and provide you the code. That isn't what we as a site are here for: it's your homework or your "paid work" (it doesn't matter which it is) and that means that it's your task, not ours. We are willing to help, but not to the extent of you getting rewarded for our effort!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Here's my App.xaml
<Application x:Class="WPF_WindowStyle.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPF_WindowStyle"
StartupUri="MainWindow.xaml">
<Application.Resources>
<Style x:Key="CustomWindow" TargetType="{x:Type Window}">
<Setter Property="WindowStyle" Value="None"/>
<Setter Property="AllowsTransparency" Value="True"/>
<Setter Property="MinWidth" Value="100"/>
<Setter Property="MinHeight" Value="46"/>
<!--CaptionHeight + ResizeBorderThickness * 2-->
<Setter Property="Background" Value="Yellow"/>
<Setter Property="BorderBrush" Value="Green"/>
<Setter Property="BorderThickness" Value="5"/>
<Setter Property="Foreground" Value="DarkRed"/>
<Setter Property="Template" Value="{StaticResource WindowTemplate}"/>
</Style>
</Application.Resources>
</Application>
Here's my MainWindow.xaml
<Window x:Class="WPF_WindowStyle.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPF_WindowStyle"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525" Style="{StaticResource RedWindow}">
<Grid>
</Grid>
</Window>
I've got a fail in MainWindow.xaml where Style="{StaticResource RedWindow}" is highlighted in red .
I understand that I have no RedWindow resource at all. However, what I need to do in this case.
Thanks in advance!
|
|
|
|
|
Pew_new wrote: <Style x:Key="CustomWindow" Pew_new wrote: Style="{StaticResource RedWindow}"
That's a mistake in the text of the sample you're following. The {StaticResource ...} key needs to match the <Style x:Key="..." key. Change the window style to:
Style="{StaticResource CustomWindow}"
Resources - The complete WPF tutorial[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
And I've got a fail in App.xaml right after changing to CustomWindow .
<setter property="Template" <code="">Value="{StaticResource WindowTemplate}"/>
|
|
|
|
|
That resource seems to be missing from the text of the code sample. You'll probably need to download the code to see it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|