小编Dan*_*Lip的帖子

有没有更快的方式从网站下载内容?

这是我现在的代码:

private string downloadContent() 
        {
            try
            {
                WebRequest request = WebRequest.Create(url);
                request.Method = "GET";
                response = request.GetResponse();
                Stream stream = response.GetResponseStream();
                reader = new StreamReader(stream);
                string content = reader.ReadToEnd();
                return content;
            }
            catch
            {
                return error;
            }
        }
Run Code Online (Sandbox Code Playgroud)

这是网站:

http://chatroll.com/testings
Run Code Online (Sandbox Code Playgroud)

当我在聊天中写一些内容时,我就这样做,这样每隔n秒它就会显示我在程序textBox1中写的内容,并将其写在我硬盘上的文本文件记录器中.

问题是有时候如果我在聊天中输入的东西非常快(例如:你好(输入),嗨(输入),丹尼尔(输入))有时你的程序中不会显示你好.我不认为我输入内容的内容读得足够快.

有没有更快的方式来下载页面源并处理它?也许我下载它的方式不是那么快?

你可以在这里看到我的项目:

https://skydrive.live.com/redir?resid=3B8A7D9F66FF985B!171&authkey=!AFO6EmoF38MtkKQ

c#

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

为什么按名称的特定进程不在我创建的列表中?

我有这个功能,我检查过程是否已启动以及何时退出.但我在IF上使用断点并且列表计数始终为0.

当我运行任务amanager我看到有bf3.exe*32所以这里有什么问题?

private void isProcessRunning()
{                
    Process[] proclist = Process.GetProcessesByName("bf3.exe");

    if (proclist.Length > 0)
    {
        Logger.Write("Battlefield 3 Started");
        alreadyRun = true;
    }
    else if (alreadyRun == true)
    {
        Logger.Write("Battlefield 3 Exited");
    }            
}
Run Code Online (Sandbox Code Playgroud)

c#

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

在 HtmlAgilityPack 中加载 url 到文档时,如何添加 webRequest 以设置超时?

加载 url 时我有这个代码:

private List<string> test(string url, int levels,DoWorkEventArgs eve)
        {
            HtmlWeb hw = new HtmlWeb();
            List<string> webSites;
            try
            {
                this.Invoke(new MethodInvoker(delegate { Texts(richTextBox1, "Loading The Url: " + url + "..." , Color.Red); }));
                doc = hw.Load(url);
                this.Invoke(new MethodInvoker(delegate { Texts(richTextBox1, "Done " + Environment.NewLine, Color.Red); }));
Run Code Online (Sandbox Code Playgroud)

有时,当它加载 url 时,它会花费很多时间,因为 url 变量中的网站没有响应。我想添加一个超时,所以让我们说 X 秒后它会抛出一条消息,比如“有一个超时”。

现在 HtmlAgilityPack 没有任何超时属性或类。所以我想在我的 Form1 中创建一个新函数,它将使用 webrequest 和 webresponde 并在这个新函数中设置一个超时,然后在加载 url 之前调用这个函数。

有人可以告诉我如何使新函数与我的代码一起使用吗?也有超时。

谢谢。

c# html-agility-pack

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

如何将float转换为int?

cube1.name = string.Format("Terrain_{0}_{1}", 
    (int)Terrain.activeTerrain.transform.position.x + tilePositionInLocalSpace.x, 
    (int)Terrain.activeTerrain.transform.position.z + tilePositionInLocalSpace.y);
Run Code Online (Sandbox Code Playgroud)

试图把它投下来,int但没有太大变化.每个多维数据集的名称仍然是例如:Terrain_6.5_5.5.但我想要这个名字Terrain_6_5.

tilePositionInLocalSpacevector3类型,x都是float类型.

c# unity-game-engine unity5

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

为什么获取以及如何修复 ffmpeg 上的警告/错误:没有足够的帧来估计速率;考虑增加探针尺寸?

我正在使用的命令:

ffmpeg -f gdigrab -framerate 24 -i desktop -preset ultrafast -pix_fmt yuv420p camera1.mp4
Run Code Online (Sandbox Code Playgroud)

Stream #0:没有足够的帧来估计速率;考虑增加探针尺寸

并且 :

不推荐使用 AVStream.codec 将编解码器参数传递给多路复用器,请改用 AVStream.codecpar。

然后一直:

过去的持续时间 0.810524 太大

一些信息:

ffmpeg -f gdigrab -framerate 24 -i desktop -preset ultrafast -pix_fmt yuv420p camera1.mp4 ffmpeg 版本 N-81045-g450cf40 版权所有 (c) 2000-2016 FFmpeg 开发人员使用 gcc 5.4.0 (GCC) 配置构建--enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-libebur128 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger - -enable-libsnappy …

ffmpeg

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

为什么循环没有从列表中删除所有不以“CM”开头的项目?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
using System.Linq;

public class CamerasInfo : MonoBehaviour
{
    public List<CinemachineFreeLook> FreeLook;
    public List<CinemachineVirtualCamera> Virtual;
    public List<Camera> AllCameras;
    public List<string> currentActiveCameras;

    // Start is called before the first frame update
    void Start()
    {
        Cameras();
    }

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

    public void Cameras()
    {
        FreeLook = FindObjectsOfType<CinemachineFreeLook>().ToList();
        Virtual = FindObjectsOfType<CinemachineVirtualCamera>().ToList();
        for(int i = 0; i < Virtual.Count; i++)
        {
            if (!Virtual[i].name.StartsWith("CM"))
                Virtual.RemoveAt(i);
        }

        AllCameras = Camera.allCameras.ToList();

        foreach …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

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

我收到 UnityException 纹理不可读。何,我应该处理它吗?

我不明白这个异常以及如何修复它。

例外情况在第 38 行:

pixels = origTex.GetPixels();
Run Code Online (Sandbox Code Playgroud)

完整的异常消息:

UnityException:纹理“screen_1920x1080_2021-07-09_14-08-00”不可读,无法从脚本访问纹理内存。您可以在纹理导入设置中使纹理可读。

我不知道如何处理。在此之前,这是我第一次遇到此异常。

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

public class RawImagePixelsChange : MonoBehaviour
{
    // Create a blank RawImage and drag this script onto it

    // NOTE: Unless you create a new texture from the image (instead of using it directly),
    // changes will alter the asset itself!
    // Textures must be type 2D/UI and have Read/Write enabled

    // Unity docs say GetPixels32 etc. is faster, but I wasn't able …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

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

如何使用网络客户端计算并显示下载速度?

目标是在下载时计算并在 label4.Text 上显示下载速度。

private void Download()
        {
            using (var client = new WebClient())
            {
                client.DownloadFileCompleted += (s, e) => label1.Text = "Download file completed.";
                client.DownloadProgressChanged += (s, e) => progressBar1.Value = e.ProgressPercentage;
                client.DownloadProgressChanged += (s, e) => label2.Text = FormatBytes(e.BytesReceived);
                client.DownloadProgressChanged += (s, e) => label4.Text = e.
                client.DownloadProgressChanged += (s, e) =>
                {
                    label3.Text = "%" + e.ProgressPercentage.ToString();
                    label3.Left = Math.Min(
                        (int)(progressBar1.Left + e.ProgressPercentage / 100f * progressBar1.Width),
                        progressBar1.Width - label3.Width
                    );                   
                };

                client.DownloadFileAsync(new Uri("https://speed.hetzner.de/10GB.bin"), @"d:\10GB.bin");
            }
        } 
Run Code Online (Sandbox Code Playgroud)

在带有 …

c# unity-game-engine

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

为什么会出现错误 SerializedObjectNotCreatableException: 索引 0 处的对象为 null 和 InvalidCastException: 指定的转换无效。?

错误中没有任何脚本的任何特定行。我尝试向我的角色添加动画,然后删除动画并将其从动画控制器中删除,然后发生了错误。

我从层次结构中删除了所有内容,也在资产中删除了我安装的任何包资产。仍然显示错误。

我在昨天开始的另一个项目中也遇到了这个错误。

我正在使用 unity 2021.3.2f1 个人版

每个错误显示两次相同的错误:

SerializedObjectNotCreatableException:索引 0 处的对象为空 UnityEditor.Editor.CreateSerializedObject () (at :0) UnityEditor.Editor.GetSerializedObjectInternal () (at :0) UnityEditor.Editor.get_serializedObject () (at :0) UnityEditor.BaseAssetImporterTabUI.get_serializedObject ( )(在:0) UnityEditor.ModelImporterClipEditor.UnregisterListeners()(在:0) UnityEditor.ModelImporterClipEditor.OnDisable()(在:0) UnityEditor.ModelImporterEditor.OnDisable()(在:0)

InvalidCastException:指定的强制转换无效。UnityEditor.AssetImporters.AssetImporterEditor.InitializePostprocessors () (在:0) UnityEditor.AssetImporters.AssetImporterEditor.OnEnable () (在:0) UnityEditor.AssetImporterTabbedEditor.OnEnable () (在:0) UnityEditor.ModelImporterEditor.OnEnable () (在:0) 0)

unity-game-engine

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

如何使文件夹名称为001,002,003?

else if (currentLightningFolderPath != null)
{
    int currentLightningEndFrame = processedFrames;
    string frameRange = $"[{currentLightningStartFrame:D4}-{currentLightningEndFrame:D4}]";
    string lightningFolderName = $"Lightning{"D3"}_{frameRange}";
    Directory.Move(currentLightningFolderPath, Path.Combine(selectedFolderPath, lightningFolderName));
    currentLightningFolderPath = null;
    framesCaptured = 0; // Reset the counter
}
Run Code Online (Sandbox Code Playgroud)

我以为“D3”可以做到这一点,但硬盘上的文件夹名称是:

LightningD3_ 和下一个也以 LightningD3_ 开头

我希望文件夹以 Lightning001_ 开头,然后是 Lightning002_ 等等。

c# winforms

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