小编Biz*_*han的帖子

COM异常80040154创建Excel应用程序时

我正在尝试在没有安装Office的服务器上运行我的应用程序.

using EXCEL = Microsoft.Office.Interop.Excel;
...
EXCEL.Application app = new EXCEL.Application();//Exception thrown here
Run Code Online (Sandbox Code Playgroud)

代码在我自己的系统上工作正常,但在服务器上它提供以下异常:

Unhandled Exception: System.Runtime.InteropServices.COMException: 
Retrieving the COM class factory for component with CLSID {...} failed
due to the following error: 80040154 Class not registered
(Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
Run Code Online (Sandbox Code Playgroud)

两个系统都是32位,我在应用程序的exe旁边复制了excel Interop dll.我也安装了O2010PIA.

任何铅?

c# com interop com-interop office-interop

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

Process.Start("microsoft-edge:") 在 dot net core 中抛出 Win32Exception

当我执行以下代码行时:

Process.Start("microsoft-edge:");
Run Code Online (Sandbox Code Playgroud)

或者

Process.Start("microsoft-edge:http://localhost");
Run Code Online (Sandbox Code Playgroud)

它给了我这个错误:

System.ComponentModel.Win32Exception: '系统找不到指定的文件。'

当我microsoft-edge:使用Win+运行时,R它可以工作。

当我在 .net 框架中运行相同的代码时,它可以工作。

我正在使用 .netcore 3.0.0-preview6-27804-01

知道为什么会这样吗?


编辑:

这些也不起作用:

Process.Start(@"c:\Windows\System32\LaunchWinApp.exe:http://localhost");
Process.Start(@"http://localhost");
Run Code Online (Sandbox Code Playgroud)

我系统上的所有其他可执行文件都可以工作。

这也有效,但我无法用它打开特定网页:

Process.Start("explorer", @"shell:Appsfolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge");
Run Code Online (Sandbox Code Playgroud)

c# process .net-core microsoft-edge

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

在动画和脚本中为游戏对象设置动画

我有一个横向滚动的 2D 游戏。玩家(名为Default)是一只会说话的鸟,它的四肢都是会说话的鸟,移动的四肢之一是它的眼球(名为pupil),它有一个名为 的脚本EyeController

在此处输入图片说明

我想要做的是:

  • 案例 1:鸟应该盯着目标变换并用眼睛跟随它。(这是在EyeController脚本中的代码中完成的。您可以在我的问题末尾找到它)
  • 情况 2:当我在 Bird 的动画师中设置触发器时,它会启动眼球动画,并且还有另一个触发器可以转到默认动画。(见下图,两个箭头出来,所以触发器可以随时改变动画)Any State

问题是:情况 1 仅在没有动画播放时才有效。一旦动画开始,它就会停止用眼睛跟随。

虽然案例 2 总是有效,并且以某种方式防止学生从代码中改变。

我希望代码覆盖动画。

鸟类动画师结构:

在此处输入图片说明

播放器具有 3 层动画。

  1. 基础层是可添加的并为翅膀设置动画。
  2. Mouth 被权重 1 覆盖并动画说话(嘴巴、瞳孔和眉毛)。
  3. 腿被权重 1 覆盖并且里面没有任何东西

正如你在下面看到的那样,在图层中的默认说话默认眼球 状态下,瞳孔.位置是动画的Mouth

Not Talking状态(Mouth图层中的默认状态,此处未显示其动画)具有空动画。

在此处输入图片说明

我做了什么:

我关闭Write Defaults了所有动画。我知道它会重置动画师范围内的动画值。

当设置了一些触发器时,动画工作并且瞳孔正确地动画;但是,当我在脚本中更改 student.localPosition 时,它不会更改瞳孔的 localPosition。

EyeController脚本的一部分:

//sight controller calls …
Run Code Online (Sandbox Code Playgroud)

animation unity-game-engine

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

在C#流上使用DisposeAsync的正确方法

我正在写一个异步将单独的文本行写入文件的方法。如果取消,它将删除创建的文件并跳出循环。

这是简化的代码,可以正常工作。。。我标记了2点,我不确定它们是如何处理的。我希望代码在任何情况下都不会阻塞线程。

public async Task<IErrorResult> WriteToFileAsync(string filePath,
                                                 CancellationToken cancellationToken)
{
    cancellationToken.ThrowIfCancellationRequested();

    using var stream = new FileStream(filePath, FileMode.Create);
    using var writer = new StreamWriter(stream, Encoding.UTF8);

    foreach (var line in Lines)
    {
        if (cancellationToken.IsCancellationRequested)
        {
            //
            // [1] close, delete and throw if cancelled
            //
            writer.Close();
            stream.Close();
            if (File.Exists(filePath))
                File.Delete(filePath);
            throw new OperationCanceledException();
        }

        // write to the stream
        await writer.WriteLineAsync(line.ToString());
    }

    //
    // [2] flush and let them dispose
    //
    await writer.FlushAsync();
    await stream.FlushAsync();
    // await stream.DisposeAsync();
    return …
Run Code Online (Sandbox Code Playgroud)

c# asynchronous stream

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

如何正确使用 CharacterController.Move() 移动角色

我创建了一个基本的第一人称控制器,但我的问题是当我向前和向侧面移动时,我移动得更快。

我如何在 1 个 Vector3 中添加moveDirectionForwardmoveDirectionSide以便能够使用CharacterController.Move()而不是 CharacterController.SimpleMove()

void MovePlayer() {

    // Get Horizontal and Vertical Input
    float horizontalInput = Input.GetAxis ("Horizontal");
    float verticalInput = Input.GetAxis ("Vertical");

    // Calculate the Direction to Move based on the tranform of the Player
    Vector3 moveDirectionForward = transform.forward * verticalInput * walkSpeed * Time.deltaTime;
    Vector3 moveDirectionSide = transform.right * horizontalInput * walkSpeed * Time.deltaTime;

    // Apply Movement to Player
    myCharacterController.SimpleMove (moveDirectionForward + moveDirectionSide);
Run Code Online (Sandbox Code Playgroud)

c# vector unity-game-engine

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

如何强制c ++编译器使用寄存器?

我的for(c ++ .Net Win32控制台)代码中有一个循环,必须尽可能快地运行.所以我需要让编译器使用寄存器而不是将其存储在RAM中.

MSDN说:

register关键字指定变量将存储在机器寄存器中(如果可能).

这是我试过的:

for(register int i = 0; i < Size; i++)
Run Code Online (Sandbox Code Playgroud)

当我查看编译器生成的反汇编代码时,我看到:

012D4484  mov         esi,dword ptr [std::_Facetptr<std::codecvt<char,char,int> >::_Psave+24h (12DC5E4h)]  
012D448A  xor         ecx,ecx  
012D448C  push        edi  
012D448D  mov         edi,dword ptr [std::_Facetptr<std::codecvt<char,char,int> >::_Psave+10h (12DC5D0h)]  
012D4493  mov         dword ptr [Size],ebx  
012D4496  test        ebx,ebx  
012D4498  jle         FindBestAdd+48h (12D44B8h)  //FindBestAdd is the function the loop is in
012D449A  lea         ebx,[ebx]  
Run Code Online (Sandbox Code Playgroud)

我期望汇编代码不生成dword ptr我使用register关键字的地方.

所以,我怎么会知道,如果有可能的编译器使用寄存器,我应该怎么做才能强制编译器直接读取/从/到寄存器写.

c++ compiler-construction performance assembly cpu-registers

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

Unity在空旷的场景中占用100%的CPU

为什么当我们使用unity3d构建游戏场景时,它会使用100%的CPU?

我的意思是,这不是一个包含许多对象和事物的场景,也不是一个空的场景,在这两种情况下,CPU使用率均为100%。

为什么?

我该如何减少呢?

我想减少CPU使用率的原因是:我想exe在专用服务器上运行多个游戏,以统一制作多人游戏。UNET在这种情况下,除了一些功能之外,我什么syncvars都没有,甚至没有更新功能……我只想让此exe文件使用更少的CPU来更好地运行并提高性能。

是否可以减少CPU使用率?

cpu performance exe cpu-usage unity-game-engine

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

引发事件 c# 给出错误:没有重载匹配委托 EventHandler

我正在尝试制作一个在发生某些事情时引发的事件。因此,包含对引发事件的类的引用的其他类会得到通知。这是我到目前为止所得到的:

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DropArea : MonoBehaviour {

    public event EventHandler ObjectChange;

    void Start () {
    }

    // Update is called once per frame
    void Update () {
    }

    void OnTriggerEnter(Collider other)
    {
        var correctType = FindParentWithComponent(other.gameObject);
        if (correctType != null)
        {
            var cc = correctType.GetComponent<Object_properties>();
            if(cc.VariableTypeSelector == AcceptedVariableType)
            {
                DetectedObjectChange(null); // here i want to raise the event
            }
        }
    }

    protected virtual void DetectedObjectChange(EventArgs e)
    {
        EventHandler handler = ObjectChange;
        if …
Run Code Online (Sandbox Code Playgroud)

c# events delegates unity-game-engine

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

wpf content 打印一个文本框

我正在使用 WPF 开发文本编辑器,并尝试使用以下代码来打印文本框的内容:

PrintDialog pd = new PrintDialog();
if ((pd.ShowDialog() == true))
{
    RichTextBox richTB = new RichTextBox();
    richTB.Document.Blocks.Add(new Paragraph(new Run(TBXEditor.Text)));

    //use either one of the below      
    pd.PrintVisual(richTB as Visual, "printing as visual");
    pd.PrintDocument((((IDocumentPaginatorSource)richTB.Document).DocumentPaginator), "printing as paginator");
}
Run Code Online (Sandbox Code Playgroud)

它不好用。如果我单击打印菜单一次,我会打印两张并且没有左边距。行首的文本未完全打印

有没有人有更好的解决方案?

printing wpf textbox

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