小编loo*_*oop的帖子

c#中的垃圾收集误区

我搜索谷歌没有得到我想要的东西.我不知道我是对还是错.看,我试图了解GC.Collect()所以这里是代码..

public class SomePublisher
{
    public event EventHandler SomeEvent;
}

public class SomeSubscriber
{
    public static int Count;

    public SomeSubscriber(SomePublisher publisher)
    {
        publisher.SomeEvent += new EventHandler(publisher_SomeEvent);
    }

    ~SomeSubscriber()
    {
        SomeSubscriber.Count++;
    }

    private void publisher_SomeEvent(object sender, EventArgs e)
    {
        // TODO: something
    }
}
Run Code Online (Sandbox Code Playgroud)

我在我的主线程中这样做..

 SomePublisher publisher = new SomePublisher();

        for (int i = 0; i < 10; i++)
        {
            SomeSubscriber subscriber = new SomeSubscriber(publisher);
            subscriber = null;
        }

        GC.Collect();
        GC.WaitForPendingFinalizers();

        Console.WriteLine(SomeSubscriber.Count.ToString());
        Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)

我得到输出0,但根据我应该是10,因为GC.Collect()必须从内存中删除class1对象,所以必须调用class1析构函数,所以计数必须增加到10 ..可以任何正文解释这个..

.net c# garbage-collection

4
推荐指数
1
解决办法
531
查看次数

异步并等待返回类型混淆

你好朋友我想知道一些异步方法的返回类型对其行为的影响,就像我有一个方法叫做methodasync1()之类的

private async void methodasync1(filename)
{
    await getfileaysnc(filename);
}
Run Code Online (Sandbox Code Playgroud)

和其他函数methodasync2()一样

private async Task methodasync2(filename)
{
    await getfileasync(filename);
}
Run Code Online (Sandbox Code Playgroud)

两种功能都以相同的方式工作或存在任何差异.以及我应该知道的任何概念,请告诉我任何想法和帮助表示赞赏

.net c# asynchronous async-await windows-8

4
推荐指数
1
解决办法
596
查看次数

使用 HttpClient 的进度信息

我想在 Windows Phone 8.1 Silverlight 中使用“Windows.Web.Http.HttpClient”实现进度条。

编辑:第一次尝试

private async Task CheckProgress()
{
    var df = httpClient.GetAsync(new Uri(uriString, UriKind.Absolute)).Progress = Progress;

    // here i want to stop the execution till whole content downloaded

    // Reason to wait here
    // this client download will be used by one more async method. so i need to wait here till the file completely downloaded.

    // this whole is done in this method only ( requirement)
} 

private void  Progress(IAsyncOperationWithProgress<HttpResponseMessage, HttpProgress> asyncInfo, HttpProgress progressInfo) …
Run Code Online (Sandbox Code Playgroud)

c# asynchronous httpclient windows-phone-8.1

4
推荐指数
1
解决办法
6877
查看次数

在手机上查看互联网连接

我想检查一下我的手机是否可以连接到互联网.我已经看过几个问题.其中一个是问题.它说使用NetworkInterface.GetIsNetworkAvailable()这个,我尝试了.我已将我的电脑与互联网断开连接,并且还关闭DataConnection了模拟器,但这NetworkInterface.GetIsNetworkAvailable()始终是真的.但同时我也检查NetworkInterfaceType.None并有趣地它将变为空.任何人都可以解释我在哪里缺少信息?

尝试: -

public static void CheckNetworkAvailability()
    {
       // this is coming true even when i disconnected my pc from internet.
       // i also make the dataconnection off of the emulator
        var fg = NetworkInterface.GetIsNetworkAvailable();

        var ni = NetworkInterface.NetworkInterfaceType;
        // this part is coming none  
        if (ni == NetworkInterfaceType.None)
            IsConnected = false;

    }
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏:)

.net c# windows-phone-8 windows-phone-8.1 windows-phone-sl-8.1

4
推荐指数
2
解决办法
4559
查看次数

使用xamarin进行原生开发

我只是Xamarin的初学者,任何机构可以用更简单的方式解释我这里的陈述: -

Access to native APIs Allows you to create native apps with device-specific experiences.

这是否意味着无论Android开发人员能做什么,Java例如关于设备api的所有内容等等,我都可以使用Xamarinin 来做同样的事情C#

c# xamarin xamarin.forms

4
推荐指数
1
解决办法
365
查看次数

使用通知中心注册两个模板并发送通知

动机: - 我想同时向我的Windows Phone 8.1应用程序发送Toast和Tile Notification.

=>我正在使用带有通知中心的模板功能来发送本地化通知.

当我只使用Notificationhub客户端注册Toast/Tile模板(一次一个)时,一切正常.

await _hubClient.CreateWindowsTemplateRegistrationAsync(model.ChannelUri, toasttemplate, tags);
Run Code Online (Sandbox Code Playgroud)

问题: - 但是当我使用集线器注册Both Toast和Tile模板时,那么在这种情况下它无法发送两个通知.没有错误指示..

所以任何人都知道如何同时注册和发送两个通知?任何指针或帮助真的很感激.

notifications azure windows-phone-8 azure-notificationhub windows-phone-8.1

4
推荐指数
1
解决办法
1611
查看次数

Windows Phone 8.1中的后台代理(Silverlight)

我正在关注此链接以在WP 8.1 Silverlight中实现ScheduledAgent.

脚步 :-

编辑WMAppManifest.xaml:

<Tasks>
  <DefaultTask Name="_default" NavigationPage="/View/StartPage.xaml" />
  <ExtendedTask Name="BackgroundTask">
    <BackgroundServiceAgent Specifier="ScheduledTaskAgent" Name="ScheduledTaskAgent2" Source="ScheduledTaskAgent2" Type="ScheduledTaskAgent2.ScheduledAgent" />
  </ExtendedTask>
</Tasks>
Run Code Online (Sandbox Code Playgroud)

添加了具有目标版本8.1的新ScheduledAgent项目.: 在此输入图像描述

现在我的ScheduledAgent类

#define DEBUG_AGENT
using System;
using System.Diagnostics;
using System.Windows;
using Microsoft.Phone.Scheduler;
using Microsoft.Phone.Shell;

namespace ScheduledTaskAgent2
{
    public class ScheduledAgent : ScheduledTaskAgent
    {

         protected override void OnInvoke(ScheduledTask task)
         { 

#if DEBUG_AGENT
            ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(60));
#endif
            NotifyComplete();         

          }
    }
}
Run Code Online (Sandbox Code Playgroud)

我的代码启动代理

public const string PeriodicTaskName = "ScheduledTaskAgent2";
private PeriodicTask _periodicTask;

    private void StartPeriodicAgent()
    {
        _isPeriodicTaskStarted = true; …
Run Code Online (Sandbox Code Playgroud)

c# silverlight scheduled-tasks windows-phone-8.1

3
推荐指数
1
解决办法
1173
查看次数

取消令牌的使用

我正在尝试学习如何使用取消令牌取消任务.在这里,我已经为它写了一个UnitTest,但我没有得到它的工作方式.

[TestMethod]
public async Task Task_should_not_run_when_token_cancelled_before_its_call()
{
    var cts = new CancellationTokenSource();
    var token = cts.Token;

    cts.Cancel();

    Debug.WriteLine("Calling Cancellable Method".ToUpper());
    try
    {
        await CheckMeCalled(token);
    }
    catch (Exception expException)
    {

    }
}

private async Task CheckMeCalled(CancellationToken ct)
{
    Debug.WriteLine("Before task delayed".ToUpper());
    await Task.Delay(5000);
    Debug.WriteLine("After task delayed".ToUpper());
}
Run Code Online (Sandbox Code Playgroud)

在上面的测试i中调用cts.Cancel()之前调用CheckMeCalled方法.所以它不应该取消运行.但它正在全力以赴.

我在某处读过

cts.Cancel().

但这似乎并没有发生在这里.有人可以向我解释一下吗?任何帮助表示赞赏.欢呼:)

.net c# async-await windows-phone-8 cancellation-token

2
推荐指数
1
解决办法
1767
查看次数

将String转换为Page的类型?

我想将字符串DashBoard转换为一种名为DashBoard的页面,因为我想在导航中使用它.通常我会导航到这样的页面

this.Frame.Navigate(typeof(DashBoard));
Run Code Online (Sandbox Code Playgroud)

但我想将DashBoard页面替换为这样的变量

this.Frame.Navigate(typeof(Somestring));
Run Code Online (Sandbox Code Playgroud)

c# navigation windows-8 windows-store-apps

1
推荐指数
1
解决办法
1601
查看次数

Xamarin.Android vs Android

我是C#男人,并试图探索Xamarin制作Android应用程序使用C#(保持冷静的Java家伙:).

所以我的问题是 -

  • 除了语言用法之外,它们之间有什么区别吗?
  • 与实际Android相比,使用Xamarin.Android有任何限制吗?
  • 我可以使用Xamarin.Android做任何事情,因为我们可以使用Android Java吗?

c# android xamarin

1
推荐指数
1
解决办法
1352
查看次数

内存不足...在Windows Phone 8中

我试图从Windows Phone 8的照片库中获取图像,并且它第一次正常工作.我第一次从Camera Roll文件夹中获取图像,但是当我尝试从相册Saved Picture中拍摄图片时,它会抛出Out of Memory Exception ..我不明白为什么会发生这种情况.任何帮助表示赞赏.

    MediaImage mediaImage = new MediaImage();


    BitmapImage image;
    private void Panorama_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
    {
        Panorama obj = sender as Panorama;
        PanoramaItem objPanoramaItem = (PanoramaItem)obj.SelectedItem;
        string FolderName = objPanoramaItem.Header.ToString();
        PictureAlbum AlbumFolder = allAlbums.Where(album => album.Name == FolderName).FirstOrDefault();
        if (FolderName == "Camera Roll")
        {
            if (ImageListCameraRoll == null)
            {
                ImageListCameraRoll = new ObservableCollection<MediaImage>();



                var CameraRollPictures = AlbumFolder.Pictures;

                foreach (var picture in CameraRollPictures)
                {
                    mediaImage = new MediaImage();
                    image = new BitmapImage(); …
Run Code Online (Sandbox Code Playgroud)

.net c# windows-phone-7 windows-phone-8

0
推荐指数
1
解决办法
1197
查看次数