Tagged: WinCE

WinCE 同步时间

最近项目中PDA的时间总是与业务数据时间不符,因此需要一个这样的功能。

首先确定使用WebService的Response信息作为时间的获取源头。

代码如下

#region 修改系统日期
[DllImport("coredll.dll")]
private static extern bool SetLocalTime(ref SystemTime lpSystemTime);

public struct SystemTime
{
    public short wYear;
    public short wMonth;
    public short wDayOfWeek;
    public short wDay;
    public short wHour;
    public short wMinute;
    public short wSecond;
    public short wMilliseconds;
}

/// <summary>
/// 设置系统当前日期
/// </summary>
public static void SetTime()
{

    WebRequest request = null;
    WebResponse response = null;
    WebHeaderCollection headerCollection = null;

    string webserviceUrl = string.Format("http://{0}/axis/servlet/AxisServlet", DB.GetServerAddr());
    string datetime = string.Empty;
    CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture("en-US");
    // Tue, 11 Sep 2018 09:46:58 GMT
    string format = "r";

    try
    {
        request = WebRequest.Create(webserviceUrl);
        request.Timeout = -1;
        request.Credentials = CredentialCache.DefaultCredentials;
        response = request.GetResponse();
        headerCollection = response.Headers;
        foreach (var item in headerCollection.AllKeys)
        {
            if (item.Equals("Date",StringComparison.CurrentCultureIgnoreCase))
            {
                datetime = headerCollection[item];
            }
        }

        SystemTime newTime = new SystemTime();
        DateTime dt = DateTime.ParseExact(datetime, format, cultureInfo).AddHours(8.00);

        newTime.wYear = Convert.ToInt16(dt.Year);
        newTime.wMonth = Convert.ToInt16(dt.Month);
        newTime.wDay = Convert.ToInt16(dt.Day);
        newTime.wDayOfWeek = Convert.ToInt16(dt.DayOfWeek);
        newTime.wHour = Convert.ToInt16(dt.Hour);
        newTime.wMinute = Convert.ToInt16(dt.Minute);
        newTime.wSecond = Convert.ToInt16(dt.Second);

        SetLocalTime(ref newTime);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    finally
    {
        if (request != null)
        {
            request.Abort();
        }
        if (response != null)
        {
            response.Close();
        }
        if (headerCollection != null)
        {
            headerCollection.Clear();
        }
    }
}
#endregion

VS2008编译WinCE程序过慢解决办法

VS2008环境下采用C#、.NET Compact Framework开发WinCE、Windows Mobile程序时,编译项目非常慢,有时候需要几分钟甚至十几分钟,如果出现这种情况,除了排除机器配置问题外,你可以修改VS的配置文件,以屏蔽掉编译中不需要的任务,这个修改可以让你的编译速度大大提高,有可能你的编译时间只需要几秒钟就搞定了啊。

1、找到以下文件

%windir%\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.Common.targets

2、用记事本打开该文件,找到以下节点,在target树节点上增加 Condition="'$(SkipPlatformVerification)' == 'true'" 修改后的内容如下。

<Target Name="PlatformVerificationTask" Condition="'$(SkipPlatformVerification)' == 'true'" >
  <PlatformVerificationTask
    PlatformFamilyName="$(PlatformFamilyName)"
    PlatformID="$(PlatformID)"
    SourceAssembly="@(IntermediateAssembly)"
    ReferencePath="@(ReferencePath)"
    TreatWarningsAsErrors="$(TreatWarningsAsErrors)"
    PlatformVersion="$(TargetFrameworkVersion)"/>
</Target>

具体可以参考:https://blogs.msdn.microsoft.com/vsdteam/2006/09/15/platform-verification-task/