当前位置:首页 » 编程语言 » c语言可以同时运行两个子程序吗
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言可以同时运行两个子程序吗

发布时间: 2023-05-28 22:40:42

1. c语言中如何让两个程序同时运行

C语言中语句的执行是线性的,就是说执行完一条在执行下一条,所以。。。

2. C语言怎么实现同时运行两个子程序

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace _2
{
public partial class Form1 : Form
{
public Form1()
{
Control. = false;//忽略错误线程
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Thread t1 = new Thread(new ThreadStart(run1));
t1.Start();
Thread t2 = new Thread(new ThreadStart(run2));
t2.Start();
}
public void run1()
{
while (1 == 1)
{
int i1 = label1.Location.X;
Random rd = new Random();
int i = rd.Next(19);
i1 = i1 + i;
Point p = new Point(i1, label1.Location.Y);
Thread.Sleep(22);
if (label1.Left >= this.Size.Width - label1.Size.Width)
{
Thread.CurrentThread.Abort();
}
}
//while (1 == 1)
//{
// Random rd = new Random();
// int i = rd.Next(19);
// label1.Left += i;
// Thread.Sleep(22);
// if (label1.Left >= this.Size.Width - label1.Size.Width)
// {
// Thread.CurrentThread.Abort();
// }
//}
}
public void run2()
{
int i1 = label1.Location.X;
int i2 = label2.Location.X;
//while (1 == 1)
//{
// Random rd = new Random();
// int i = rd.Next(19);
// label2.Left += i;
// Thread.Sleep(22);
// if (label2.Left >= (this.Size.Width - label2.Size.Width))
// {
// Thread.CurrentThread.Abort();
// }
//}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
}

}
}

3. C语言如何同时运行两个子函数

同时执行,使用线程了
C语言本身没有提供线程的功能,只能调用平台的线程来实现
如果在 WINDOWS 下面,可以参考一下 CreateThread 方法

4. 怎样用c语言实现多任务同时运行,急.......

用个API函数。
包函头文件 window.h
CreateThread(NULL,0,FunPro,NULL,0,NULL);

你再写个线程函数 FunPro

int WINAPI FunPro()
{
return 0;
}

大概是这样,我也没写过,你自己再去网络下。

5. c语言中如何同时运行多个源文件

第一步:

将源文件1(1.c)修改为如下形式:

#include "print.h"
#include "2.c"
int main(void)
{
printHello();
return 0;
}

其中的2.c就是源文件2的文件名

第二步,将三个文件保存到同一目录中

第三步,打开TC2,执行FILE-CHANGE DIR,将工作目录换到三个文件所在的目录。

第四步,在TC2中打开1.c文件,编译运行。

建议不要再使用TC2这个相对原始的IDE了,上面介绍的这个方法也并不是标准方法,建议使用TC2006/VC/BCB等现代的IDE环境,如果实在是舍弃不下DOS字符界面,那就试试GCC吧!