RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-283644

serjou's questions

Martin Hope
serjou
Asked: 2020-03-08 17:28:26 +0000 UTC

为什么从 View 接收到的对象与从那里传递的对象不同?

  • 0

我有一个 ASP.NET Core MVC 应用程序。有一个用于编辑组的表格。

来自控制器的代码:

    public IActionResult EditGroup(int? id)
    {
        if (id != null)
        {
            var group = _unitOfWork.Groups.Get((int)id);
            if (group != null)
                return View(group);
        }
        return NotFound();
    }
    [HttpPost]
    public IActionResult EditGroupPost(Group group)
    {
        _unitOfWork.Groups.Update(group);
        _unitOfWork.Save();
        return RedirectToAction("Index");
    }

查看代码:

@model University.Core.Models.Group
@{
    ViewData["Title"] = "EditGroup";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h1>Edit Group</h1>


<form asp-action="EditGroupPost" asp-controller="home" asp-route-id="@Model.Id">
    <div class="form-group">
        <label asp-for="Name" class="control-label">Name</label>
        <input type="text" asp-for="Name" class="form-control" />
    </div>
    <div class="form-group">
        <input type="submit" value="Save" class="btn btn-default" />
    </div>
</form>

团体课:

public class Group
{
    public int Id { get; set; }
    public int CourseId { get; set; }
    public string Name { get; set; }
}

输入Group值为CourseId1 的视图,离开值为 0 的视图

可能是什么原因?

mvc
  • 1 个回答
  • 10 Views
Martin Hope
serjou
Asked: 2020-09-27 13:05:35 +0000 UTC

选择两个 ListView 项时如何激活按钮?WPF

  • 1

有一个 ListView 和一个按钮来比较两个项目,当两个项目被选中时,这两个项目应该是活动的。有这个XAML代码:

<Button Command="{Binding CompareSnapshots}"
    CommandParameter="{Binding SelectedItems, ElementName=SnapshotsListView}"
    IsEnabled="{Binding SelectedItems, ElementName=SnapshotsListView, Converter={StaticResource selectedItemCollectionToBoolConverter}}"
    Content="Compare"
    HorizontalAlignment="Stretch"
    VerticalAlignment="Top"
    Margin="0,10,0,0"
    Width="130"
    Height="60"
    Grid.Column="1"/>

转换器:

class SelectedItemCollectionToBoolConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (((IList<object>)value).Count == 2)
            return true;
        else
            return false;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

问题是绑定仅在应用程序启动时才有效。怎么修?

c#
  • 1 个回答
  • 10 Views
Martin Hope
serjou
Asked: 2020-09-24 19:23:14 +0000 UTC

如何对 ListView 项目进行分组?wpf

  • 0

问题很简单。我需要将我的ListView(其中GridView)分组到这样的地方:在此处输入图像描述

问题是我铲了一堆文章,到处都用到了很多代码Code-Behind(甚至在构造函数中也经常设置一个集合)。我需要一个正常的MVVM解决方案。

c#
  • 1 个回答
  • 10 Views
Martin Hope
serjou
Asked: 2020-03-26 22:16:05 +0000 UTC

Windows 窗体 C# 窗体的显示不正确

  • 0

问题是这样的:在调整表单大小并添加几个元素后,当程序启动时,表单显示得比需要的小。该属性FormBorderStyle设置为FixedDialog。如果您将其设置为 ,窗口将以正确的大小显示Sizable。经过搜索,发现Designer.cs属性ClientSize设置为较小的尺寸,当我将其更改为所需的尺寸时(371, 256),窗口变成了正确的尺寸,但同时Size属性中的值变大了(389, 303),并且在设计师的形式变得比必要的大。可能是什么问题呢?

在此处输入图像描述 在此处输入图像描述

c#
  • 1 个回答
  • 10 Views
Martin Hope
serjou
Asked: 2020-03-10 21:33:46 +0000 UTC

扫描注册表。递归和线程。C#

  • 1

再会!

我正在编写一个程序,我需要在其中扫描整个注册表。我决定递归地进行,就像我对文件和文件夹所做的那样,它们被扫描了大约 20 秒。结果,以下代码出现在某处:

class AllRegistryPermissions
    {
        public Dictionary<string, StringDictionary> HKCRKeys;
        public Dictionary<string, StringDictionary> HKCUKeys;
        public Dictionary<string, StringDictionary> HKLMKeys;

        static List<string> FPK;

        static public void GetRegistry(Dictionary<string, StringDictionary> Keys, RegistryKey ParentKey)
        {
            string Name = ParentKey.Name;
            if (!((Properties.Settings.Default.RFilterPathList.Contains(Name)) || (FPK.Any(t => Name.Contains(t)))))  //фильтрация по пути и по ключевым словам
            {
                if (ParentKey.ValueCount != 0)
                {
                    Keys.Add(ParentKey.Name, new StringDictionary());
                    foreach (string name in ParentKey.GetValueNames())
                    {
                        Keys[ParentKey.Name].Add(name, ParentKey.GetValue(name, "!!! Cant identify value !!!").ToString());
                    }
                }
                else Keys.Add(ParentKey.Name, null);

                if (ParentKey.SubKeyCount != 0)
                {
                    foreach (string name in ParentKey.GetSubKeyNames())
                    {
                        try
                        {
                            if (ParentKey.OpenSubKey(name) != null) GetRegistry(Keys, ParentKey.OpenSubKey(name));
                        }
                        catch (System.Security.SecurityException) { }
                    }
                }
            }
        }

        public AllRegistryPermissions()
        {
            FPK = Properties.Settings.Default.RFilterKeywordList.Cast<string>().ToList();
            HKCRKeys = new Dictionary<string, StringDictionary>();
            GetRegistry(HKCRKeys, Registry.ClassesRoot);
            HKCUKeys = new Dictionary<string, StringDictionary>();
            GetRegistry(HKCUKeys, Registry.CurrentUser);
            HKLMKeys = new Dictionary<string, StringDictionary>();
            GetRegistry(HKLMKeys, Registry.LocalMachine);
        }
    }

他扫描正常,但仅扫描一根树枝就HKCR需要五分钟。结果显然不适合我(因为同一个 Systracer 会在 20-30 秒内扫描所有内容),我考虑了多线程。经过长时间的巫术(我想我已经从一个heowolder至少成长为一个bydlocker),代码开始看起来像这样:

class AllRegistryPermissions
    {
        public ConcurrentDictionary<string, StringDictionary> HKCRKeys;
        public ConcurrentDictionary<string, StringDictionary> HKCUKeys;
        public ConcurrentDictionary<string, StringDictionary> HKLMKeys;

        static CountdownEvent ce;
        static int maxtasks = 0;
        static int cantopen = 0;
        static int cantopensec = 0;

        static List<string> FPK;

        static public void GetRegistry(ConcurrentDictionary<string, StringDictionary> Keys, RegistryKey ParentKey)
        {
            string Name = ParentKey.Name;
            if (!((Properties.Settings.Default.RFilterPathList.Contains(Name)) || (FPK.Any(t => Name.Contains(t)))))
            {
                int close = 0;
                if (ParentKey.ValueCount != 0) 
                {
                    ce.AddCount();
                    if (ce.CurrentCount > maxtasks) maxtasks = ce.CurrentCount;
                    Task.Run(() =>
                    {                        
                        Keys.GetOrAdd(ParentKey.Name, new StringDictionary());
                        foreach (string name in ParentKey.GetValueNames())
                        {
                            Keys[ParentKey.Name].Add(name, ParentKey.GetValue(name, "!!! Cant identify value !!!").ToString());
                        }
                        close++;
                        if (close == 2) ParentKey.Close();
                        ce.Signal();
                    });
                }
                else
                {
                    Keys.GetOrAdd(ParentKey.Name, (StringDictionary)null);
                    close++;
                }

                if (ParentKey.SubKeyCount != 0)
                {
                    ce.AddCount();
                    if (ce.CurrentCount > maxtasks) maxtasks = ce.CurrentCount;
                    Task.Run(() =>
                    {
                        foreach (string name in ParentKey.GetSubKeyNames())
                        {
                            try { if (ParentKey.OpenSubKey(name) != null) GetRegistry(Keys, ParentKey.OpenSubKey(name));
                                else cantopen++; }
                            catch (System.Security.SecurityException) {
                                cantopensec++; }
                        }
                        close++;
                        if (close == 2) ParentKey.Close();
                        ce.Signal();
                    });
                }
                else close++;
            }
        }

        public AllRegistryPermissions()
        {
            FPK = Properties.Settings.Default.RFilterKeywordList.Cast<string>().ToList();
            ce = new CountdownEvent(3);
            Task hkcrTask = Task.Run(() =>
            {
                HKCRKeys = new ConcurrentDictionary<string, StringDictionary>();
                GetRegistry(HKCRKeys, Registry.ClassesRoot);
                ce.Signal();
            });
            Task hkcuTask = Task.Run(() =>
            {
                HKCUKeys = new ConcurrentDictionary<string, StringDictionary>();
                GetRegistry(HKCUKeys, Registry.CurrentUser);
                ce.Signal();
            });
            Task hklmTask = Task.Run(() =>
            {
                HKLMKeys = new ConcurrentDictionary<string, StringDictionary>();
                GetRegistry(HKLMKeys, Registry.LocalMachine);
                ce.Signal();
            });            
             ce.Wait();
            Console.WriteLine("maximal tasks numbers: " + maxtasks);
            Console.WriteLine("can't open {0} subkeys", cantopen);
            Console.WriteLine("can't open {0} subkeys sec", cantopensec);
        }
    }

一切都会好起来的,但我觉得这一点都不好,也不对。我是第一次使用多线程,我不知道一次正常运行多少线程。谷歌搜索一点看到1-4。我的代码最多同时运行了130,000 个线程,我怀疑这非常糟糕(我以为计算机会爆炸)。但设计师在一分钟内完成了工作。
问题是,我该如何解决这个问题?不知何故重新编写代码,调节线程数,改变方法本身或用另一种语言重写代码(我听说C ++在这方面更快)?
该程序将使用该类的两个实例来比较并找出哪些键已被删除、添加或更改。

c#
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5