Skip to content

Commit

Permalink
push msdn code gallery community-a-c
Browse files Browse the repository at this point in the history
  • Loading branch information
Terry Fei (Pactera) committed Nov 12, 2019
1 parent c2ecd1a commit 3e88636
Show file tree
Hide file tree
Showing 45,988 changed files with 12,691,729 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
79 changes: 79 additions & 0 deletions A Simple Timer for windows8 App C#/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# A Simple Timer for windows8 App C#
## Requires
- Visual Studio 2012
## License
- MS-LPL
## Technologies
- C#
- Windows 8
- Visual Studio 2012
- Windows 8 Store Apps
- Windows Store app
## Topics
- A Timer for windows8 App
## Updated
- 05/04/2013
## Description

<h1>Introduction</h1>
<p><em>Explicitly there is no Timer control in VS2012 for windows store apps. This Sample gives a solution for this, by implementing a simple timer.</em></p>
<p><span style="font-size:20px; font-weight:bold">Description</span></p>
<p><em>A timer can be created with the help of the DispatcherTimer class.</em></p>
<p><em>Main Functionality:</em></p>
<p><em>For every n seconds (you specify as the timer interval), the Tick event is Fired untill the timer is stopped.</em></p>
<p><em>Many of the young developers having doubts related to timer like,&nbsp;</em></p>
<p><em>How to implement a Timer in windows8 App?</em></p>
<p><em>How to start and stop a Timer ?</em></p>
<p><em>The sample gives &nbsp;answer to all timer related questions in a simple and easy way.<br>
<br>
</em></p>
<p><em>&nbsp;</em></p>
<p><em>Only a few steps in implementation,</em></p>
<p><em>1, Create a object for the DispatcherTimer class.</em></p>
<p><em>2,Associate a Event &quot;Tick&quot; with the created object using the below code.</em></p>
<p><strong><em>&nbsp; &nbsp; timer.Tick &#43;= timer_Tick();</em></strong></p>
<p><em>3,Set a timer Interval for which periodically the Tick event is Fired(when the Timer is On) using the below line.</em></p>
<p><em><strong>&nbsp;&nbsp;&nbsp; timer.Interval = TimeSpan.FromSeconds(5);</strong>// here is set the interval as 5 seconds</em></p>
<p><em>4, Then define the <strong>timer_tick </strong>method according to your own usage(In my sample i just displayed the time consumed).</em></p>
<p><em><br>
</em></p>
<p><em><br>
</em></p>
<p><em>&nbsp;</em></p>
<p>&nbsp;</p>
<div class="scriptcode">
<div class="pluginEditHolder" pluginCommand="mceScriptCode">
<div class="title"><span>C#</span></div>
<div class="pluginLinkHolder"><span class="pluginEditHolderLink">Edit</span>|<span class="pluginRemoveHolderLink">Remove</span></div>
<span class="hidden">csharp</span>

<div class="preview">
<pre class="csharp">&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cs__keyword">private</span>&nbsp;DispatcherTimer&nbsp;timer;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cs__keyword">private</span>&nbsp;<span class="cs__keyword">int</span>&nbsp;i,j;&nbsp;
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timer&nbsp;=&nbsp;<span class="cs__keyword">new</span>&nbsp;DispatcherTimer();&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timer.Tick&nbsp;&#43;=&nbsp;timer_Tick;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timer.Interval&nbsp;=&nbsp;TimeSpan.FromSeconds(i);&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cs__keyword">void</span>&nbsp;timer_Tick(<span class="cs__keyword">object</span>&nbsp;sender,&nbsp;<span class="cs__keyword">object</span>&nbsp;e)&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TimerTextBlock.Text&nbsp;=&nbsp;<span class="cs__string">&quot;Time&nbsp;Consumed:&nbsp;&quot;</span>&nbsp;&#43;&nbsp;(i)&nbsp;&#43;&nbsp;<span class="cs__string">&quot;&nbsp;second(s)&quot;</span>;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i&nbsp;=&nbsp;i&nbsp;&#43;&nbsp;j;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</pre>
</div>
</div>
</div>
<h1><span>Source Code Files</span></h1>
<p><em>Only a few steps in implementation,</em></p>
<p><em>1, Create a object for the DispatcherTimer class.</em></p>
<p><em>2,Associate a Event &quot;Tick&quot; with the created object using the below code.</em></p>
<p><em>&nbsp; timer.Tick &#43;= timer_Tick();</em></p>
<p><em>3,Set a timer Interval for which periodically the Tick event is Fired(when the Timer is On) using the below line.</em></p>
<p><em>&nbsp;&nbsp;&nbsp; timer.Interval = TimeSpan.FromSeconds(5);// here is set the interval as 5 seconds</em></p>
<p><em>4, Then define the timer_tick method according to your own usage(In my sample i just displayed the time consumed).</em></p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "A Simple Timer for windows8 App", "A Simple Timer for windows8 App\A Simple Timer for windows8 App.csproj", "{A6B778BE-9AB1-4DFD-9595-C58A8174526A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|ARM = Debug|ARM
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|ARM = Release|ARM
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Debug|ARM.ActiveCfg = Debug|ARM
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Debug|ARM.Build.0 = Debug|ARM
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Debug|ARM.Deploy.0 = Debug|ARM
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Debug|x64.ActiveCfg = Debug|x64
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Debug|x64.Build.0 = Debug|x64
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Debug|x64.Deploy.0 = Debug|x64
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Debug|x86.ActiveCfg = Debug|x86
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Debug|x86.Build.0 = Debug|x86
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Debug|x86.Deploy.0 = Debug|x86
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Release|Any CPU.Build.0 = Release|Any CPU
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Release|Any CPU.Deploy.0 = Release|Any CPU
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Release|ARM.ActiveCfg = Release|ARM
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Release|ARM.Build.0 = Release|ARM
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Release|ARM.Deploy.0 = Release|ARM
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Release|x64.ActiveCfg = Release|x64
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Release|x64.Build.0 = Release|x64
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Release|x64.Deploy.0 = Release|x64
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Release|x86.ActiveCfg = Release|x86
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Release|x86.Build.0 = Release|x86
{A6B778BE-9AB1-4DFD-9595-C58A8174526A}.Release|x86.Deploy.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A6B778BE-9AB1-4DFD-9595-C58A8174526A}</ProjectGuid>
<OutputType>AppContainerExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>A_Simple_Timer_for_windows8_App</RootNamespace>
<AssemblyName>A Simple Timer for windows8 App</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<PackageCertificateKeyFile>A Simple Timer for windows8 App_TemporaryKey.pfx</PackageCertificateKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
<OutputPath>bin\ARM\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<!-- A reference to the entire .Net Framework and Windows SDK are automatically included -->
</ItemGroup>
<ItemGroup>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
<None Include="A Simple Timer for windows8 App_TemporaryKey.pfx" />
</ItemGroup>
<ItemGroup>
<Content Include="Assets\Logo.png" />
<Content Include="Assets\SmallLogo.png" />
<Content Include="Assets\SplashScreen.png" />
<Content Include="Assets\StoreLogo.png" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="Common\StandardStyles.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="MainPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '11.0' ">
<VisualStudioVersion>11.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Application
x:Class="A_Simple_Timer_for_windows8_App.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:A_Simple_Timer_for_windows8_App">

<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>

<!--
Styles that define common aspects of the platform look and feel
Required by Visual Studio project and item templates
-->
<ResourceDictionary Source="Common/StandardStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>

</ResourceDictionary>
</Application.Resources>
</Application>
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227

namespace A_Simple_Timer_for_windows8_App
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
sealed partial class App : Application
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
}

/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used when the application is launched to open a specific file, to display
/// search results, and so forth.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
Frame rootFrame = Window.Current.Content as Frame;

// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();

if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}

// Place the frame in the current Window
Window.Current.Content = rootFrame;
}

if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
if (!rootFrame.Navigate(typeof(MainPage), args.Arguments))
{
throw new Exception("Failed to create initial page");
}
}
// Ensure the current window is active
Window.Current.Activate();
}

/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity
deferral.Complete();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3e88636

Please sign in to comment.