小编Krz*_*nek的帖子

Windows Phone 8.1 MediaCapture会冻结手机

我想制作一个简单的应用程序,这将允许我检查每个预览框架的几个参数,但我遇到了运行和停止预览.

    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        MediaCapture _MediaCapture;
        bool _recording;
        public MainPage()
        {
            this.InitializeComponent();

            this.NavigationCacheMode = NavigationCacheMode.Required;
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param> …
Run Code Online (Sandbox Code Playgroud)

c# deployment camera visual-studio-2013 windows-phone-8.1

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

"在WPF上找不到IPlatformOperations.这绝不会发生,你的依赖解析器会被破坏"

我正在编写一个程序,它是其他较小程序的容器.它通过Assembly.Load加载它的模块,找到实现IModule的类型并创建它们的实例.

在WPF MainWindow中,我有一个RoutedViewHost,它将显示所有内容.

在我的AppBoostrapper中,我有以下内容:

     private ReactiveList<IModule> LoadModules(IMutableDependencyResolver resolver)
        {
            var modules = ModuleLoader.Load(ModulesDirectory);
//                        var modules = new IModule[] { new SampleModuleClass(), }; // this works perftectly!

            foreach (var module in modules)
            {
                try
                {
                    module.RegisterDependencies(this, resolver);
                }
                catch (Exception e)
                {
                    Log.Error(e, "Could not register dependecies for module " + module.Name);
                }
            }

            Log.Debug("Modules loaded: " + string.Join(", ", modules.Select(x => x.Name)));
            return new ReactiveList<IModule>(modules);
        }
Run Code Online (Sandbox Code Playgroud)

然后,在我的示例模块中:

  public void RegisterDependencies(IMainScreen screen, IMutableDependencyResolver resolver)
        {
            _screen = screen;
            _resolver = …
Run Code Online (Sandbox Code Playgroud)

c# wpf .net-assembly reactiveui mahapps.metro

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

如何在 Entity Framework Core cli 工具中使用 dotnet 6 最小 API 的配置

我正在尝试使用 EF Core 构建一个 API 作为数据库访问,现在在 dotnet 6 RC1 上。我想使用 dotnet cli 工具来管理迁移(创建、更新数据库等),但这些工具不与模板中的最小 API 配合。

这是我的 Program.cs:

void ConfigureApp(WebApplication webApplication)
{
    // Configure the HTTP request pipeline.
    if (webApplication.Environment.IsDevelopment())
    {
        webApplication.UseSwagger();
        webApplication.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Eyespert.Server v1"));
    }

    webApplication.UseHttpsRedirection();

    webApplication.UseAuthentication();
    webApplication.UseAuthorization();

    webApplication.MapControllers();
}

void RegisterServices(WebApplicationBuilder builder)
{
    builder.Services.AddControllers();
    builder.Services.AddSwaggerGen(c =>
    {
        c.SwaggerDoc("v1", new() { Title = "App", Version = "v1" });
    });
    
    builder.Services.AddDbContext<MyContext>(opt =>
    {
        string connectionString = builder.Configuration.GetConnectionString("MyConnectionString");
        opt.UseNpgsql(connectionString);
    });
}

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

RegisterServices(builder);

WebApplication app = builder.Build(); …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-core asp.net-core .net-6.0

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

WPF 图像控件不处理源

我已经阅读了有关此的多个线程,但仍然找不到任何有效的内容。

我正在编写基本上浏览图像数据库的程序。我有一个带有 DataTemplate 的 ListView:

<DataTemplate>
        <Grid Width="Auto" Height="Auto" >
            <Image VerticalAlignment="Center" Source="{Binding IsAsync=True,
 Converter={StaticResource Converter},
 ConverterParameter={x:Static viewModel:SearchViewModel.MiniaturesHeight}}"
 Grid.RowSpan="2"  Stretch="None" Margin="5" 
Height="{Binding Source={StaticResource Locator}, Path=MiniaturesHeight}" 
Width="{Binding Source={StaticResource Locator}, Path=MiniaturesHeight}"
 RenderOptions.BitmapScalingMode="NearestNeighbor" />
             <TextBlock Text="{Binding Name}" Margin="5" />
        </Grid>
    </DataTemplate>
Run Code Online (Sandbox Code Playgroud)

在转换器中,我接收对象并根据其内容创建 URL。我的问题是我需要每页显示 100 个图像,例如整个数据库有 40k 个图像。我想允许用户单击所有页面而不会出现 StackOveflowException。不幸的是,每次我更改页面时,内存使用量都会增加并且不会下降,即使我等待很长时间也是如此。

程序本身使用大约 60MB 的 RAM,但在更改页面 5 次后,它的 RAM 达到 150MB,并且稳步上升。

这是我的第一个转换器:

  public class ObjectToUrl : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return DependencyProperty.UnsetValue;

            var obj …
Run Code Online (Sandbox Code Playgroud)

c# data-binding wpf xaml

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

ReactiveUI 测试中的调度程序

因此,当我为我的系统开发新功能时,我也尝试进行 TDD - 遗憾的是,现在为旧功能执行此操作的代码太大了。

然而,我发现有时我在测试过程中会碰壁——尤其是在使用Delay和时Throttle

我读了很多书,我想我比一周前知道了更多,但我想把所有这些付诸实践。我写了一些实验:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Reactive;
    using System.Reactive.Concurrency;
    using System.Reactive.Linq;
    using System.Reactive.Threading.Tasks;
    using System.Text;
    using System.Threading.Tasks;
    using Microsoft.Reactive.Testing;
    using NUnit.Framework;
    using NUnit.Framework.Internal.Commands;
    using ReactiveUI;
    using ReactiveUI.Testing;

    namespace UtilsTests
    {
        [TestFixture]
        public class SchedulersTests
        {
            private int SecondsN = 1;

            [Test]
            public async Task NoScheduler()
            {
                var t = Observable.Return(Unit.Default).Delay(TimeSpan.FromSeconds(SecondsN), RxApp.MainThreadScheduler)
                    .ObserveOn(RxApp.MainThreadScheduler)
                    .ToTask();
                await t;
            }

            [Test]
            public Task ImmediateSchedulerExperiment()
            {
                return Scheduler.Immediate.With(async s =>
                {
                    var t = …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing system.reactive reactiveui

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

在 Xeon/nVidia Quadro 机器上创建 WPF 位图图像非常慢

我写了一个 WPF 程序,它是事物的图形浏览器。它在 ListView 中显示了相当多的图像,每个图像都带有图像控件。它还允许用户进行基本的图像编辑。

我已经在许多不同的机器上运行过这个软件:我的开发笔记本电脑,我同事的 MacBook 和并行桌面,VirtualBox VM,可以通过 Windows 远程桌面访问,甚至在 10 年前的笔记本电脑上。它运行得很好。

不幸的是,我们的第一个客户是设计公司,拥有专为 CAD 设计构建的工作站,配备至强处理器和 nVidia Quadro 2000 卡。现在震惊了:我的程序在他们的机器上太慢以至于无法使用。

我用过dotTrace,发现瓶颈是我的ImageToImageSourceConverter,这是最标准的一个:

  public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        Bitmap bmp = value as Bitmap;
        if (bmp == null)
            return null;

        using (MemoryStream memory = new MemoryStream())
        {
            memory.Seek(0, SeekOrigin.Begin);
            bmp.Save(memory, ImageFormat.Bmp);
            memory.Position = 0;
            BitmapImage bitmapImage = new BitmapImage();
            bitmapImage.BeginInit();
            bitmapImage.StreamSource = memory;
            bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
            bitmapImage.EndInit();
            return bitmapImage;
        }
Run Code Online (Sandbox Code Playgroud)

dotTrace 表明,在他们的机器上,带有 bitmapImage.EndInit() 的行占用了大量的计算时间。它也是在 ui 线程上完成的,因此应用程序会冻结一段时间。dotTrace …

c# wpf performance image nvidia

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

从C#调用Delphi DLL并传递位图和字节数组

我试图用C#调用几个Delphi函数:

  MyType =array [1 .. 124] of byte
  procedure f(bytes: MyType); stdcall;
  external 'my.dll' name 'f';
Run Code Online (Sandbox Code Playgroud)

那是我的第一个问题.我试过了:

    [DllImport("Delphi/my.dll",
        CallingConvention = CallingConvention.StdCall,
        CharSet = CharSet.Auto)]
    public static extern
    void sygLadSyg([MarshalAs(UnmanagedType.LPArray)] byte[] myArray);
    void sygLadSyg([MarshalAs(UnmanagedType.SafeArray)] byte[] myArray); 
Run Code Online (Sandbox Code Playgroud)

我得到例外:

对PInvoke函数的调用使堆栈失衡.这很可能是因为托管PInvoke签名与非托管目标签名不匹配.检查PInvoke签名的调用约定和参数是否与目标非托管签名匹配.

我究竟做错了什么?

第二个问题是传递位图.

function sygAnaliz(bitmapa: TBitmap): byte; stdcall;
  external 'awSygnat1.dll' name 'sygAnaliz';
 [DllImport("Delphi/awSygnat1.dll",
            CallingConvention = CallingConvention.StdCall,
            CharSet = CharSet.Ansi)]
        public static extern
        byte sygAnaliz(IntPtr bitmapPtr);
// and call itself
sygAnaliz(firstIMG.GetHbitmap());
Run Code Online (Sandbox Code Playgroud)

我得到异常:尝试读取或写入受保护的内存.这通常表明其他内存已损坏.

这两种功能都是内存安全的,因为它们已经使用了几年而效果很好.也许有一些我想念的东西?

c# delphi interop bitmap marshalling

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